laravel5.4 using Migration database migration to build a table

Source: Internet
Author: User

First of all, make sure that the database link in the Laravel. env file is created, and here I'm using the MySQL database

1 db_connection=mysql   // database 2 db_host=127.0.0.1  // Server IP Address 3 db_port=3306    // database Port 4 db_database=larvael54  // Database name 5 db_username=root   // database user name 6 db_password=root  //  Database Password

Here I'm using the PHP Storm command line input to create the migration command, such as creating the Users table

PHP Artisan make:migration create_users_table

Note: Creating a migration file named Create_ table name _table creates a successful creation in the Migrations directory under the database directory.

2017_12_6_205846_create_users_table.php file, open file input code
<?PHP UseIlluminate\support\facades\schema; UseIlluminate\database\schema\blueprint; Useilluminate\database\migrations\migration;classCreateuserstableextendsmigration{/** * Run the migrations. * * @return void*/     Public functionUp () {Schema:: Create (' users ',function(Blueprint$table) {//Here is the field property of the table you want to create$table->increments (' id '); $table-string(' Name '); $table-string(' email ')Unique (); $table-string(' Password '); $table-Remembertoken (); $table-timestamps ();    }); }    /** * Reverse the migrations. * * @return void*/     Public functionDown () {Schema::d ropifexists (' users '); }}

When the file is created successfully, enter it on the PHP storm command line

PHP Artisan Migrate

After execution completes, the build table succeeds.

laravel5.4 using Migration database migration to build a table

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.