4

I've just started using Laravel and I'm having trouble with artisan and migrations.

I create a migration using: php artisan migrate:make create_clubs_table. I am able to then create a db schema.

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?

4

1 回答 1

2

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.

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.

于 2013-10-16T21:22:58.133 回答