1

I'm publishing a website ASP.NET MVC and get this error:

“Migrations is enabled for context ‘Context’ 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 can't install visual studio on server so i can't run ‘Update-Database’ command.

How to solve this problem ?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Take a look at this questions: http://stackoverflow.com/questions/10848746/using-entity-framework-code-first-migrations-in-production http://stackoverflow.com/questions/9281423/entity-framework-4-3-run-migrations-at-application-start – Jojo Feb 18 '14 at 10:02

2 Answers2

1
  1. Find migrate.exe (YourApp\packages\EntityFramework.6.1.3\tools) and paste it in bin folder on the server.
  2. Open Command Prompt on the server.
  3. Run below commands

    cd "C:\Websites\YourApp\bin" migrate.exe YourAppName.Api.dll /startupconfigurationfile:..\Web.config /verbose

Please Note that YourAppName.Api.dll should be the DLL having Enabled Migration.

Luzan Baral
  • 3,678
  • 5
  • 37
  • 68
  • I have this problem: ERROR: Could not load assembly 'Update-Database'. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.) – d3roch4 May 10 '22 at 14:19
-1

you do not need to install visual studio on the server.

if you have your database connection string setup in web.config you should be able to run update-database in the package manager console and it will update your database on your web host.

Matt Tabor
  • 1,053
  • 8
  • 10