Create a data migration
To create a migration using the Artisan command-line migrate:make
command: (used in command-line mode)
PHP Artisan Migrate:make create_users_table
All migrations are stored app/database/migrations
under Folders, and files are named with timestamps to facilitate the laravel framework to define these file sequences by time.
You can use the options when creating a migration to --path
specify the path where the migrated files will be stored. This path is the relative path to the root directory of your installation framework:
PHP Artisan migrate:make Foo--path=app/migrations
--table
and --create
options to specify the table name and whether to create a new table:
PHP artisan migrate:make add_votes_to_user_table--table=usersphp artisan migrate:make create_users_table--create= Users
Run Data migrationRun all migrations (keep all your tables up to date)
PHP Artisan Migrate
Run all migrations under a path (Specify migration file path)
PHP Artisan Migrate--path=app/foo/migrations
Run all migrations under a package (used when installing or upgrading an extension package corresponding to the database)
PHP Artisan Migrate--package=vendor/package
Note: If you receive a "Class not found" error while running the migration, try running the composer dump-autoload
command.
Enforcing data migration in a production environment
Some migration operations are disruptive and can cause you to lose legacy data in your database. To prevent unnecessary damage from running such commands, these commands will ask you if you are sure you want to do this. If you want to run such a command without prompting, you can use the --force
option:
PHP Artisan Migrate--force
Rollback data migration (even if rollback, the original data is destroyed, can only roll back the table structure, so do not take this function as a lifeline)Roll back the last migration
PHP Artisan Migrate:rollback
Don't worry: Run composer Dump-autoload
Try again, OK. See figure.
Roll back all migrations
PHP Artisan Migrate:reset
Roll back all migrations and rerun data migration
PHP artisan migrate:refreshphp Artisan Migrate:refresh--seed
Laravel Database Migration Error Resolution