Search code examples
sqlversion-controlredgate

Redgate migration scripts not running on deployment


I've been reading through the Redgate documentation on migration scripts and I'm trying to add a new column to a table that has a foreign key from another table.

Here's what I have done:

  1. Added the new column, made it null-able and created the relationship to a new table then I've committed the changes.
  2. I then add static data to the new table so that the migration can run. I commit this static data.I then add a blank migration script, and set all null values on the column I've created in the last commit to be the Id of one of the records in the related table. I then commit this change.
  3. I then run a deployment of both commits to my testing environment where records already exist.

The problem I'm having is that the column gets created but the script seems like its not running as the column values stay null. I've verified that the script should actually change the columns as I've attempted to run it manually and it executes successfully.

Am I doing something wrong when using these scripts? Thanks.


Solution

  • I was creating blank migration scripts which lead to SQL Compare to set the column as not null. You have to specifically create a migration script on the schema change that requires it or SQL Compare will override all changes.