Laravel 4 - 执行 artisan:migrate 时出现致命错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19413899/
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
Laravel 4 - Getting a fatal error when performing artisan:migrate
提问by Robin
I've just started using Laravel and I'm having trouble with artisan and migrations.
我刚刚开始使用 Laravel,但在使用 artisan 和迁移时遇到了麻烦。
I create a migration using: php artisan migrate:make create_clubs_table
. I am able to then create a db schema.
我使用以下方法创建迁移:php artisan migrate:make create_clubs_table
。然后我能够创建一个数据库模式。
But when I change the schema and create a new migration using the above command I get the following error:
但是,当我使用上述命令更改架构并创建新迁移时,出现以下错误:
PHP Fatal error: Cannot redeclare class CreateClubsTable in /var/www/clubb/app/database/migrations/2013_10_16_202121_create_clubs_table.php on line 43
Now, I know it's because I now have 2 migrations with the same class name, but isn't that the idea of migrations, or am I misunderstanding the docs? Am I supposed to delete the old migrations?
现在,我知道这是因为我现在有 2 个具有相同类名的迁移,但这不是迁移的想法,还是我误解了文档?我应该删除旧的迁移吗?
采纳答案by Marwelln
I think you've got it wrong. You shouldn't create a table twice with migrations. If you for some reason must (for example: you got one migration that drops the table after you've created it), then you can name it recreate_clubs_table
or create_clubs_table_again
.
我想你弄错了。您不应该使用迁移创建两次表。如果您出于某种原因必须(例如:您有一个在创建表后删除该表的迁移),那么您可以将其命名为recreate_clubs_table
或create_clubs_table_again
.
If you only want to create it again and have no other migrations that alter that table after you've created it with the migration you can run it manually with php artisan tinker --env=local
(env
only needed if you're not in production). After you've executed the tinker
command you can run (new CreateClubsTable)->down();
followed by (new CreateClubsTable)->up();
. That will run your migration for the specific class.
如果您只想再次创建它并且在使用迁移创建该表后没有其他更改该表的迁移,您可以手动运行它php artisan tinker --env=local
(env
仅当您不在生产中时才需要)。执行tinker
命令后,您可以运行(new CreateClubsTable)->down();
后跟(new CreateClubsTable)->up();
. 这将为特定类运行迁移。