Home > Back-end >  How to delete specific migration and then remigrate that table only in Laravel?
How to delete specific migration and then remigrate that table only in Laravel?

Time:03-25

Hy there,

I entered some fields in migration file and then migrated it to phpmyadmin, but lateron I added some more fields in it but I have already entered data in the table. If I drop that table from phpmyadmin, it doesn't migrate using

php artisan migrate

if I wipe the whole database, I lose the whole data.

php artisan db:wipe

So I just want to get that added fields in my table without lossing my entered data.

Thanks in Advance, Junaid Ali

If I drop that table from phpmyadmin, it doesn't migrate using

php artisan migrate

if I wipe the whole database, I lose the whole data.

php artisan db:wipe

So I just want to get that added fields in my table without lossing my entered data.

CodePudding user response:

go to your database and open the table "migrations" then you search and delete the migration from your database and run migrates again.

If this doesn't work run this command php artisan migrate:fresh it will delete all your database and then automatically run migrations.

If this doesn't work then check in your .env if the database set is the same.

If none of this works do as @Maksim said.

CodePudding user response:

If you just wanted to add a new field to a exiting migration, you can just Generate a new Migration file then run a php artisan migrate, so that you don't have to problem about losing you existing data in your database.

ex. //your existing table

php artisan make:migration create_users_table

php artisan make:migration add_votes_to_users_table --table=users

//to add new field (vote)

then run php artisan migrate to add vote field to your users table

you can also refer to the laravel documentation for much detailed explanation about generating migrations https://laravel.com/docs/8.x/migrations

  • Related