2012-04-04 71 views
2

我試圖使用Fluent Migrator創建一個唯一的列。但是,如果我嘗試與列定義一起定義了唯一約束它不工作,例如像:在Fluent Migrator中定義唯一的約束條件

[Migration(20120404190455)] 
public class Migration1 : Migration 
{ 
    public override void Up() 
    { 
     Create.Table("Test") 
      .WithColumn("Name").AsString(64).Unique(); 
    } 

    public override void Down() 
    { 
     Delete.Table("Test"); 
    } 
} 

我執行這樣的遷移:

<sourcedir>\packages\FluentMigrator.Tools.1.0.1.0\tools\AnyCPU\40\Migrate.exe -a build\TheMigrationDLL.dll --db sqlserver2008 -conn "DQLEXPRESS;Initial Catalog=DBNAME;Trusted_Connection=True;" --verbose=true 

輸出:

connection is null! 
connection is null! 
Using Database sqlserver2008 and Connection String Data Source=.\SQLEXPRESS;Initial Catalog=DBNAME;Trusted_Connection=True; 
-- VersionMigration: migrating =============================================== 

-- CreateTable VersionInfo 
CREATE TABLE [dbo].[VersionInfo] ([Version] BIGINT NOT NULL) 
-- -> 0,0170009s 

-- VersionMigration: migrated 
-- -> 0,0190011s 

-- Migration1: migrating ===================================================== 

-- CreateTable Test 
CREATE TABLE [dbo].[Test] ([Name] NVARCHAR(64) NOT NULL) 
-- -> 0,0020002s 

-- Migration1: migrated 
-- -> 0,0030002s 

INSERT INTO [dbo].[VersionInfo] ([Version]) VALUES (20120404190455) 
-- Committing Transaction 

顯然沒有創建唯一索引。但是,如果我創建一個單獨調用索引:

Create.Index().OnTable("Test") 
    .OnColumn("Name").Ascending() 
    .WithOptions().Unique(); 

輸出:

.... 
-- CreateIndex Test (Name) 
CREATE UNIQUE INDEX [IX_Test_Name] ON [dbo].[Test] ([Name] ASC) 
.... 

我發現在GitHub上對此(如#49#83)的幾個問題,但他們均已關閉參考this pull

我不知道我是否使用了錯誤的版本。我使用NuGet提供的版本1.0.1.0。

我很欣賞提示,我在做什麼錯在這裏。提前致謝!

問候, 安德烈

回答

2

FluentMigrator 1.0.2.0解決這方面的問題,請更新您的包。

FluentMigrator 1.0.1.0於2011年9月發佈,截至昨天我們又重新正式發佈。

請記住,如果您有一個.NET 4遷移程序集以獲取fluentmigrator.tools包,那麼您的Migrate.exe版本號就是正確的。