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。
我很欣赏提示,我在做什么错在这里。提前致谢!
问候, 安德烈