Home > database >  how to add new tables to my database without losing the data of the previous tables
how to add new tables to my database without losing the data of the previous tables

Time:11-03

I want to migrate my new tables to the mysql database and I don't want to lose the data of the previous tables that already existed , which command should I use instead of php artisan migrate

CodePudding user response:

This depends on what you want to do when creating the migration file and running it using php artisan migrate :

  • Schema::create() will create a new table. Will not affect existing data
  • Schema::table() will modify your table, usually used to add columns. Will not affect the exsting data.
  • Schema::rename() will rename the table. Will not affect the exsting data.
  • Schema::drop() will delete the table. Will affect the existing data.

You will need to see the status of the migration you created earlier using :

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

CodePudding user response:

I preferred to create it in another folder from this commend

php artisan make:migration new_table_name --path=database/migrations/new_folder_name

and run migration from

php artisan migrate --path=database/migrations/new_folder_name

CodePudding user response:

When you create a migration to create a new table, Running the command php artisan migrate will not affect the other tables It will apply the new changes only. if you have migrated your tables before and you want to create a new table you can create a new migration file and run the command php artisan migrate it will create the new table only.

  • Related