The usage of laravel migration and Seeder

Source: Internet
Author: User
Tags laravel migration

1. Create and update table structures with migration

PHP artisan make:migration create_users_table--create=users
php artisan make:migration add_votes_to_users_table- -table=users
PHP Artisan Migrate

In practical applications, there are two ways of doing this:

A. Each time the database has any changes, execute the make:migration command to generate a new migration class. The advantage is that you can keep all the history of database changes.

B. Each data table corresponds to a migration class, in the class with Schema::hastable ("some_table") to determine whether the table exists, walk CREATE table or update table process. Change the time in the file name each time you modify the class.



2. Fill the test data with Seeder




-PHP Artisan db:seed Error

If we write Seeder related code, and the code is not a problem, but the execution of PHP artisan db:seed still error,

is probably because the Seeder related file or code is not associated to the Laravel project, and a PHP artisan make:seed Sometableseeder is executed once

Yes, this sometableseeder can be any of the Seeder classes you write in the database/seeds/path.

Executing PHP artisan db:seed again will not be an error.


Related Article

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.