1
votes

Writing an API and using EF Code First. It was working perfectly fine, then I moved the POCO Objects that I use to create the tables into a folder called POCO. Deleted the database as the ID's that I was using were all out for some reason, and no when I go to update the database using migrations I get the Invalid Object "dbo.sales" error and I can seem to find out what to do about this.

Can Anyone help?

1
What's the migration code look like that is failing? - Steve Greene
You want me to post the entire migration code form teh console? - Kai Mark hirst
Just the failing code from Up(), but first you should check your database initializer to make sure it creates the database (DropCreate..., CreateIfNotExist, etc). - Steve Greene
So exactly how do you do that using LocalDB?? - Kai Mark hirst
@heyyou I didtn create the database. Entity Framework did this for me. Ive dropped the database and Entity framework isnt recreating this for some reason. Ive manually done this but Im now getting a "Cannot find the object "dbo.BikeTables" because it does not exist or you do not have permissions." This is likely somethign very simple. Is there a if nto exists that is useable so that EF creates all this again? - Kai Mark hirst

1 Answers

0
votes

You deleted your database and need to create a new database. You can't update it using database migrations, as there is no database to update.

Create a new database, and enable migrations.

Code First to a New Database

edit In response to OPs comment. To create a database using code first.

This tute is great.
Getting Started with Entity Framework 6 Code First using MVC 5

It's hard for me to give you specific advice, as I'm not sure what you've done to your project.