简体   繁体   中英

ASP.NET Azure MySQL code first migrations: Table 'xxx' already exists

I have this frustrating problem when trying to enable code migrations to create DB schema on azure MySql DB i got the:

[DbConfigurationType(typeof(MySqlEFConfiguration))]

specified to my data context and also

        var configuration = new App.Migrations.Configuration();
        var migrator = new DbMigrator(configuration);
        migrator.Update();

but a simple Table that contains only ID property and a String doesnt seem to work on Azure, it says Table 'xxx' already exists, and when it doesnt it gives another error saying Specified key was too long; max key length is 767 bytes

whats wrong with the MySQL and Code First schema generation? thanks

Issue is likely...

  1. Your Entity Code
  2. Your Seed Code
  3. Table probably does already exist

I would recommend opening the Visual Studio 2015 SQL Server Object explorer and running a few queries on the tables in question or just see if those tables exist and what data is in them.

I also do not like code first migrations, for these sorts of reasons. I would recommend following this tutorial series.

https://channel9.msdn.com/Blogs/Have-you-tried-turning-it-off-and-on-again/Creating-a-Database-Project-for-Artificial-Intelligence

https://channel9.msdn.com/Blogs/Have-you-tried-turning-it-off-and-on-again/Deploying-Database-Projects-to-SQL-Azure

https://channel9.msdn.com/Blogs/raw-tech/AI-Part-3-Entity-Framework-and-Unit-Tests

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