David Johnson
David Johnson

Reputation: 163

How to remove all migrations from a Laravel project but keep the tables and fields

I've decided to remove all the migrations from a Laravel 5.7 project as I would rather create/update the tables by hand. I've realised that data can still be loaded from the database without any migration files.

Upvotes: 0

Views: 483

Answers (1)

David Johnson
David Johnson

Reputation: 163

Remove the migration files and data in the migrations table but keep the other tables and fields.

Steps modified from this SO answer.

  • Backup the database. official link for mysqldump command.
  • Delete all the files in the migrations folder \database\migrations\
  • Delete the contents of the migrations table in MySQL delete from migrations;
  • In the project folder run composer dump-autoload

If you are managing your tables by hand remember to add the

created_at timestamp NULL DEFAULT NULL

updated_at timestamp NULL DEFAULT NULL

fields to your tables if you want to use Laravels built in timestamps functionality. If you don't want to use it leave them out and add the following line to the model:

public $timestamps = false;

See this SO question for more details on the timestamps.

Upvotes: 1

Related Questions