0

Several months ago, I was working late and needed to create a new column for a postgres table. I added the column through the command line using the standard heroku/postgres commands. I quickly realized how silly this was, deleted the column and then created the necessary migration to add it.

I recently took that laravel app and created a pipeline with it as the production app. I created a new staging app and set up a database for it. When I ran the migrations, I got an error saying that a column already existed. As you may have guessed, this is the same column that I had messed up before.

Since the migration failed after the database was created, I was able to delete the column in question, rerun the migration, and everything was OK. I do not understand why the column already existed except to guess that it was some artifact of my adding it manually (there was no error in the migrations).

I am worried that this same error will happen when I push the staging code to production and have to rerun my migrations. Obviously, in the production app I can't just delete the column in question as it has data.

Any ideas as to why this would happen and what I could do to fix the issue if it arises when I push the code into production?

Joshua Foxworth
  • 1,236
  • 1
  • 22
  • 50
  • 1
    I'd have a look at your migration-files and make sure the column isn't being added more than once. – admcfajn Apr 15 '18 at 03:07
  • 1
    Check all migrations. If it is making the column in the new environment then it must have been in one of the old migrations. One way of testing it is create a fresh db and run the migrations without the one which is creating the new column. If you are getting it then you need to keep it in only one file. – Muhammad Nauman Apr 15 '18 at 05:01
  • Have a look at https://github.com/beckenrode/mysql-workbench-export-laravel-5-migrations. If you are happy with the test environment database, you could as well create all migrations from scratch. This module works in conjunction with MySQL Workbench. – Dimitri Mostrey Apr 15 '18 at 05:23
  • I checked the migration files thoroughly and there was no point where I added the column twice. The migrations worked after I deleted the column. It had to have been an artifact of manually adding the column. – Joshua Foxworth Apr 15 '18 at 13:34

0 Answers0