Skip to content
dradovic edited this page Oct 28, 2011 · 14 revisions

General

Can I upgrade from Mig# 1.* to 2.* and use it with an existing database?

Yes. Nothing has changed on the database-side (and nothing ever will). You can simply replace the 1.* dll with the new one. Most probably, your application will still compile. If not, read in CHANGES.txt what has changed and what to do. If this does not help, post a question :)

How can I find out if my application is out-of-date in relation to the database schema?

Use the FetchMigrations method of the Migrator. It return an IMigrationBatch which (since 2.*) has a UnidentifiedMigrations property. Migrations that have been executed against the database but are not contained in the application are listed there.

I’m getting a validation error for provider Y although I’m executing the migration for provider X

That’s on purpose :) Mig# is trying to push you towards portable migrations. Please read the Validation section in the Manual.

How do I specify NVARCHAR(MAX) or CLOB as the data type of a column?

Simply use DbType.String without specifying the size. Depending on the chosen provider, this translates into NVARCHAR(MAX) or CLOB.

How can I group multiple columns into one unique constraint?

There are two alternatives of achieving this:

  • When creating the table, use the same constraint name for all involved columns. For example:
              db.CreateTable("MyTable")
                  .WithNotNullableColumn("Col1", DbType.Int32).Unique("MyUniqueConstraint")
                  .WithNotNullableColumn("Col2", DbType.String).OfSize(255).Unique("MyUniqueConstraint");
                  ...
  • Or add the unique constraint after creating the table. For example:
              db.Tables["MyTable"].AddUniqueConstraint("MyUniqueConstraint")
                  .OnColumn("Col1")
                  .OnColumn("Col2");

I’m getting a Cannot insert the value NULL into column '...' when altering a column to not-nullable altough I specify a default value

The SQL Server provider can only add the default constraint after changing the column definition. Therefore, first UPDATE all NULL values to the default value, then alter the column.

I want to my multi-column primary key to be defined in a different order as the columns appear in the CreateTable statement

You need to create the table in two steps:

  1. Create the table without specifying the primary keys. For example:
              db.CreateTable("MyTable")
                  .WithNotNullableColumn("Col1", DbType.Int32)
                  .WithNotNullableColumn("Col2", DbType.String).OfSize(255);
                  ...
  2. Add the primary key to the table and specify the columns in the order you want them to appear in the PK definition:
              db.Tables["MyTable"].AddPrimaryKey()
                  .OnColumn("Col2")
                  .OnColumn("Col1");

I’m getting a validation error saying that the maximum size of the decimal data type is 28, although I know that my database platform supports more

This is a restriction of the decimal type of the CLR (see http://support.microsoft.com/kb/932288).

Compilation

The source code does not compile

This is correct. Not all projects compile straight from the repository. Namely, the NUnit projects for database platforms that have external dependencies. These dependencies cannot be committed to the repository due to licensing and size issues. You have to download and install them yourself. For example Server Management Objects (SMO), or the SQL Server CE4 assemblies.
However, note that the main projects MigSharp and MigSharp.NUnit should always compile in a fresh check-out.

How to compile for .NET 3.5?

The MigSharp Visual Studio solution targets .NET 4.0. In order to compile for .NET 3.5, you need to resort to msbuild and specify /property:TargetFX=3.5 as an additional argument. Also, starting from 1.0.1, the compilation will expect ILMerge.exe to reside in MigSharp\lib. You can download ILMerge from Microsoft for free. It cannot be committed to the sources because of its license (I assume; please correct me if I’m wrong).

Migrate (Command-line Interface)

Migrate does not find any migrations in my assembly

Make sure that the assembly and Migrate match in terms of version of their MigSharp dependency. For example, if you are using Migrate 1.1.0, your assembly needs to compiled using Mig# 1.1.0.