laravel 删除表后如何重新迁移laravel迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50837543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:48:55  来源:igfitidea点击:

how to re-migrate a laravel migration after deleting the table

phplaravel

提问by Skrudox

after I've manually deleted a table in mysql, I run the command:

在我手动删除 mysql 中的表后,我运行以下命令:

php artisan migrate

and I get this:

我明白了:

Nothing to migrate.

it only works the first time, how to re-run the migration in laravel?

它只适用于第一次,如何在 Laravel 中重新运行迁移?

回答by Leo Rams

Laravel keeps a record of migrations that have been run. You need to go to the migrations table and delete the migration record. Laravel does this so that it knows which migrations have been run so that it doesn't run them again and so that in the case of a rollback, it knows the last batch of migrations which were done.

Laravel 会记录已运行的迁移。您需要转到迁移表并删除迁移记录。Laravel 这样做是为了知道已经运行了哪些迁移,这样它就不会再次运行它们,并且在回滚的情况下,它知道完成的最后一批迁移。

This may help https://laravel.com/docs/5.6/migrations

这可能会有所帮助https://laravel.com/docs/5.6/migrations

回答by Sujal Patel

Try composer dump-autoloadAND php artisan config:cache

尝试composer dump-autoloadphp artisan config:cache

if not working also Try php artisan migrate:refresh.

如果不工作也试试php artisan migrate:refresh

OR Also Delete Migration table in database.

或者也删除数据库中的迁移表。

回答by Joshua Stephen

That is the expected behaviour if you manually delete a table, because the previous batch migration job has already been deployed (in migrationstable).

如果您手动删除表,这是预期的行为,因为之前的批量迁移作业已经部署(在迁移表中)。

  • IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh.

  • IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrateagain. Also, you can try php artisan migrate --seedif you have any seeder.

  • 如果你想重新迁移所有的数据库,你可以简单地做:php artisan migrate:refresh

  • 如果您想确保您的数据库与您的最新更改保持干净,您可以删除整个数据库表并php artisan migrate再次执行。另外,php artisan migrate --seed如果你有任何播种机,你可以试试。

回答by Militaru

If you delete a table by hand, will have to delete the record from "migration" table too. This way when artisan migrate checks if your migration are not in "migration" table will migrate the unregistered ones.

如果您手动删除表,也必须从“迁移”表中删除记录。这样,当 artisan migrate 检查您的迁移是否不在“迁移”表中时,将迁移未注册的迁移。

回答by Anil Stha

You can simply do: php artisan migrate: fresh to re-migrate your migration and if you have seeder data then you simply do: php artisan migrate: fresh -- seed

您可以简单地执行以下操作: php artisan migrate: fresh 重新迁移您的迁移,如果您有播种机数据,那么您只需执行以下操作: php artisan migrate: fresh -- seed