Reputation: 561
I created a MYSQL database using migrations, I added some data into it, but after that I recognized that I need to add a new column into my table.
I ran the command: 'php artisan migrate', but as it didn't work to synchronize columns, it returns there is nothing to migrate.
So I ran the command 'php artisan migrate:reset', and then ran the command 'php artisan migrate' again, database schema updated correctly but for sure I lost all my inserted data.
Now I'm just testing the application, but it would be very harmful if I found out that I should modify my database while it is runing with real data!!! What should I do in this case?
should I skip using migrations and create the Mysql database directly with wamp? or use migration, but perform any later updates directly on database without updating the migration files? or there is another solution?
Upvotes: 1
Views: 4654
Reputation: 2645
Answer
If you have already created a database table and realise you need to add more into it you can simply run: php artisan make:migration add_field_to_table_name --table=tableName
You then go into that file and create the new field. Once done simply run php artisan migrate
and it'll add the new field into the desired table without causing any data loss.
Seeders
On another note, I would strongly suggest looking into seeders. This way when you're creating a project you can always refresh your migrations (wipe your database and re-migrate your tables) and then re-input the data using seeders.
Upvotes: 7
Reputation: 566
you can create a migration to alter your tables. add new columns and more.
Upvotes: 2