Database is not getting created at first time

后端 未结 2 1128
一个人的身影
一个人的身影 2021-01-14 11:06

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.

  1. How do I ge
相关标签:
2条回答
  • 2021-01-14 11:07

    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

     PM> Update-Database
    

    DONE

    0 讨论(0)
  • 2021-01-14 11:27

    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.

    1. Generate a new migration against your local database.
    2. If you want to update your production database via SQL, run 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.
    3. Run Update-Database. This time without -Script to make the changes to your local database schema.
    4. If you didn't generate the SQL file in step 2, view your local database in SQL Server Object Explorer in Visual Studio. Right-click on the local database there and choose, "Schema Compare...". Follow the wizard to compare with your production database. In the end, you can either generate a SQL file with the necessary changes that need to be made (which again, you'd hand off to your DBA if you have one), or you can migrate to production directly from Visual Studio. However, this is not really recommended. It's always best to generate the SQL, which you or your DBA can then inspect before applying the changes live.
    0 讨论(0)
提交回复
热议问题