我想將我的新表遷移到 mysql 資料庫,并且我不想丟失之前已經存在的表的資料,我應該使用哪個命令而不是 php artisan migrate
uj5u.com熱心網友回復:
這取決于您在創建遷移檔案并使用php artisan migrate以下命令運行它時要執行的操作:
Schema::create()將創建一個新表。不會影響現有資料Schema::table()將修改您的表,通常用于添加列。不會影響現有資料。Schema::rename()將重命名表。不會影響現有資料。Schema::drop()將洗掉表。會影響現有資料。
您需要使用以下命令查看您之前創建的遷移的狀態:
php migrate:status
------ ------------------------------------------------------- -------
| Ran? | Migration | Batch |
------ ------------------------------------------------------- -------
| Yes | 2014_10_12_000000_create_users_table | 1 |
| Yes | 2014_10_12_100000_create_password_resets_table | 1 |
| Yes | 2015_10_12_100000_create_vendors_table | 1 |
| Yes | 2015_10_12_100001_create_channels_table | 1 |
| Yes | 2016_06_01_000001_create_oauth_auth_codes_table | 1 |
| Yes | 2016_06_01_000002_create_oauth_access_tokens_table | 1 |
| Yes | 2016_06_01_000003_create_oauth_refresh_tokens_table | 1 |
| Yes | 2016_06_01_000004_create_oauth_clients_table | 1 |
------ ------------------------------------------------------- -------
migrate Run the database migrations
migrate:fresh Drop all tables and re-run all migrations
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
uj5u.com熱心網友回復:
我更喜歡在這個推薦的另一個檔案夾中創建它
php artisan make:migration new_table_name --path=database/migrations/new_folder_name
并運行遷移
php artisan migrate --path=database/migrations/new_folder_name
uj5u.com熱心網友回復:
創建遷移以創建新表時,運行該命令php artisan migrate不會影響其他表,只會應用新更改。如果您之前已經遷移過表并且想要創建一個新表,您可以創建一個新的遷移檔案并運行該命令,php artisan migrate它只會創建新表。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/346466.html
