How to re-create the database using EF6?
I have tried both of following post but, i don't know why its not working and getting same error.
I have already published my sample on the web server. I am using Sql Server 2012 Express DBMS.
When i have created my application and published it on web server it was working fine. It has created database automatically. After that i have made some changes in
ApplicationDBContext and added some properties in
IdentityModes(ApplicationUser). Then I have migrated database on my Local IIS Express and it was working fine. Then I have tried to publish my sample again on web server but, this time it shows an error.
Migrations is enabled for context 'ApplicationDbContext' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console.
I have deleted the database on web server and tried again. but, still i am facing same error. Now, there is an empty database without table.
Application is creating database on User Registration.
I have also read this post and tried to call
((IObjectContextAdapter)myContext).ObjectContext.CreateDatabase() method but, still its not working.
First, automatic migrations are nice for development but it's a hugely bad idea to rely on them in production. Second, at some point you turned off automatic migrations, which is why your production database is no longer having tables created in it.
Go ahead and leave automatic migrations off; even in development it's better to know exactly what changes you're making to your database by generating a migration, seeing the code that will be executed, and only then running
Update-Database to apply those changes.
You have a number of choices in terms of getting schema updates into production, but they all boil down to roughly the same procedure.
Update-Database -Script. This will generate a SQL file with the code to run on the database to migrate the schema. Hand this off to your DBA if you have one or review the SQL code yourself and then apply it manually to your database via Management Studio.
Update-Database. This time without
-Scriptto make the changes to your local database schema.
Chris Pratt is correct BTW.
I had downloaded a project in which I needed to just run "Update-Database
Here are the quick screenshots
Then at the bottom of Visual Studio