Error While Enabling Code-First Migrations On Mobile Services Database

azure-sql-database c# ef-code-first entity-framework sql

Question

I have an Azure Mobile Services project (C# backend) that I recently created and attached to an Azure SQL database. I have been trying to enable Code-First Migrations on that backing database, but it throws errors when I try to update the database.

I ran through all of the conventional steps to enable migrations (Enable-Migrations, Add-Migration). But when I try to Update-Database, it returns the following error:

Cannot create more than one clustered index on table 'dbo.Appointments'. Drop the existing clustered index 'PK_dbo.Appointments' before creating another.

Why is this happening? There aren't any tables in my database, and the project is pretty much the default.

1
13
7/8/2015 1:13:29 PM

Popular Answer

Several of the answers about deriving from a custom entity class will work, but they are not the ideal solution. As the EF team (and others) have mentioned, you need to simply add this line to your Context Configuration constructor.

 SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());

This will remove your errors when creating migrations and allow you to update the database via powershell command.

11
12/27/2015 5:25:06 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow