1、先利用artisan建立一個可遷移的資料表模板,該指令執行後會在database/migrations目錄下產生一個檔案
php artisan make:migration create_fees_count_table --create=fees_count
2、產生的檔案包含up和down兩個方法,其中up中是包含了新增表,新增列,加入索引等等一切的描述,down比較簡單,就是刪除表,當然裡面還可以有一些其他邏輯
3、up中支援的資料表列類型,做個備註,暫時不做翻譯
Command | Description |
---|---|
$table->bigIncrements('id'); | #Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent. |
$table->bigInteger('votes'); | BIGINT equivalent for the database. |
$table->binary('data'); | BLOB equivalent for the database. |
$table->boolean(' confirmed'); | BOOLEAN equivalent for the database. |
$table->char('name', 4); | CHAR equivalent with a length. |
$table->date('created_at'); | DATE equivalent for the database. |
#$table->dateTime('created_at'); | DATETIME equivalent for the database. |
$table->decimal('amount', 5 , 2); | DECIMAL equivalent with a precision and scale. |
DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point. | |
ENUM equivalent for the database. | |
FLOAT equivalent for the database. | |
#Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent. | |
INTEGER equivalent for the database. | |
JSON equivalent for the database. | |
JSONB equivalent for the database. | |
LONGTEXT equivalent for the database. | |
MEDIUMINT equivalent for the database. | |
MEDIUMTEXT equivalent for the database. | |
Adds INTEGER taggable_id and STRING taggable_type. | #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. | ##$table-> ;tinyInteger('numbers'); |
$table->timestamp('added_on'); | |
$table->timestamps(); | |