简体   繁体   中英

EF6 Code first database table not created

I have a new database set up with this connection string:

<add name="XName" connectionString="Data Source=XX\SQLEXPRESS;Initial Catalog=XDatabase;User ID=dbo_XDatabase;Password=Password1" providerName="System.Data.SqlClient" />

I added a model, added a migration and ran update-database but the table was not created.

Here's the migration code generated:

public partial class MagicWombat : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.Languages",
            c => new
                {
                    ID = c.Guid(nullable: false),
                    Name = c.String(nullable: false, maxLength: 100),
                    Code = c.String(nullable: false, maxLength: 10),
                    IsEnabled = c.Boolean(nullable: false),
                })
            .PrimaryKey(t => t.ID);

    }

    public override void Down()
    {
        DropTable("dbo.Languages");
    }
}

Everything seemed to run successfully, including my seed method. I've tested the connection to the database and it works fine. Now if I create another migration it doesn't generate code for my table again, so it seems to think it's been created successfully when it hasn't.

Why was my table not created?

Dropping my database and re-creating it solved the issue. Weird..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM