Laravel data migration

Source: Internet
Author: User
A table has been created using data migration, and data already exists in the table. how can I add, modify, or delete a field? A table has been created using data migration, and data already exists in the table. how can I add, modify, or delete a field?

Reply content:

A table has been created using data migration, and data already exists in the table. how can I add, modify, or delete a field?

Create a new migration file. generally, we create two types of migration files: create a table and modify a table. for example, if you want to create a table, for example, you want to createusersTable, you will write:

php artisan make:migration create_users_table --create=users

If you have already executedphp artisan migrateAnd some data has been inserted. if you want to modify, add, or delete fields, you need to create a new migration file. for example, you need to addemailField

php artisan make:migration add_email_column_to_users_table --table=users

Write the content you want in the add_email_column_to_users_table file, and then execute php artisan migrate

As for the migration file, the content is written in the same way. it is clearly written in this document. you can also take a look at my tutorial:

Http://www.zhoujiping.com/scratch/fetching-data.html

In addition, you can checkmigraitonsThe record in the table, you should be able to figure out the cause of your previous error

Add Field

Schema::table('users', function ($table) {    $table->string('email');});

Modify field

Schema::table('users', function ($table) {    $table->string('name', 50)->change();});

Rename a field

Schema::table('users', function ($table) {    $table->renameColumn('from', 'to');});

Remove field

Schema::table('users', function ($table) {    $table->dropColumn('votes');});

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.