Laravel Database Migration Error Resolution

Source: Internet
Author: User
Tags autoload

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

--tableand --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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.