1. First use artisan to create a migratable data table template. After running this command, it will be in the database/migrations directory. Generate a file
php artisan make:migration create_fees_count_table --create=fees_count
2. The generated file contains two methods, up and down. Up contains descriptions of adding tables, adding columns, adding indexes, etc., and down is relatively simple, which is to delete tables. , of course there can be some other logic in it
3. The data table column types supported in up. Make a note and will not translate it for the time being
Command | Description |
---|---|
Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent. | |
BIGINT equivalent for the database. | |
BLOB equivalent for the database. | |
BOOLEAN equivalent for the database. | ##$table->char('name', 4); |
$table->date('created_at'); | |
$table->dateTime('created_at'); | |
##$table->decimal('amount', 5 , 2); | |
$table->double('column', 15, 8); | |
$table->enum('choices', ['foo', 'bar'] ); | |
$table->float('amount'); | |
$table->increments('id'); | |
$table->integer('votes'); | |
##$table->json(' options'); | JSON equivalent for the database. |
$table->jsonb('options'); | JSONB equivalent for the database. |
$table->longText('description'); | LONGTEXT equivalent for the database. |
$table->mediumInteger('numbers'); | MEDIUMINT equivalent for the database. |
##$table->mediumText('description'); | MEDIUMTEXT equivalent for the database. |
Adds INTEGER taggable_id and STRING taggable_type. | |
Same as timestamps(), except allows NULLs. | |
Adds remember_token as VARCHAR(100) NULL. | |
SMALLINT equivalent for the database. | |
Adds deleted_at column for soft deletes. | |
VARCHAR equivalent column. | |
VARCHAR equivalent with a length. | |
TEXT equivalent for the database. | |
TIME equivalent for the database. | |
TINYINT equivalent for the database. | |
TIMESTAMP equivalent for the database. | |
Adds created_at and updated_at columns. | |
UUID equivalent for the database. | |
4. After the table is created, execute it directly. Since I did not use php artisan migrate before creating many tables, running this command directly resulted in a prompt that some tables existed. Therefore, I transferred this file to the tmp directory under the database and added --path 'database/tmp' to the command. The operation is successful again | 5. Observe in the database and find that the table has been created! |
The latest five Laravel video tutorials