Running Azure Mobile Server project locally

2019-06-08 12:59发布

问题:

I'm running an Azure Mobile Server project locally with a local SQL Database. I started from the Quickstart project, but as soon as I change the Entity to something more complex, I get this error with my migration:

"Cannot create more than one clustered index on table..."

Even with the correct schema I get this other error:

"Automatic migrations that affect the location of the migrations history system table (such as default schema changes) are not supported. Please use code-based migrations for operations that affect the location of the migrations history system table."

回答1:

If you're using migrations, there's a chance that EF is trying to create both the primary key and CreatedAt column as clustered indexes. If you tell the migration to use the Azure Mobile Services/Apps SqlGenerator, it should do the right thing.

See if my answer here fixes the issue for you.



回答2:

This is an artifact of Entity Framework, the ORM that .NET Mobile Services use. It's recommended that you use Code First Migrations to address this issue. Mobile Services has a full guide which is kept up to date on how to enable code first migrations. https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations/

If you'd rather not deal with Code First Migrations, you can drop your database each time (not really a good idea for production purposes) or use the JavaScript backend.