kitloong / laravel-migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
2.46k stars 271 forks source link

Remote deployment (Forge / Deployer) not possible #54

Closed pboese closed 2 years ago

pboese commented 2 years ago

Heya and thanks for this awesome piece of code!

We have one issue: We're using Laravel Forge or Deployer (both pull the code from a git repo on the remote server) in our projects and this leads to errors when we ran the migrations generator locally, commit and push the changes and then deploy.

Because the remote server does not have the locally generated entries for the new migrations in the migrations table, the required php artisan migrate command fails (SQLSTATE[42S01]: Base table or view already exists).

Any idea how to work around this issue?

Thanks in advance!

Pelle

pboese commented 2 years ago

The only working solution I can come up with would be to create a migration that runs before the others and inserts the newly created migrations into the migrations table so they don't run

kitloong commented 2 years ago

Hello @pboese

(SQLSTATE[42S01]: Base table or view already exists)

If you run php artisan migrate in the existing schema, without migrations table, Laravel will assume it is a fresh run and try to create schema from migration files, which explains the error.

To fix that, you need some manual work:

  1. Generate migrations from local php artisan migrate:generate
  2. During the generation, be sure to answer yes for being asked Do you want to log these migrations in the migrations table?
  3. By using your preferred way, copy the generated migrations table with its records into your remote server.

Above steps should fix your issue.