How to enable the Migrations in My MVC5 Project? - asp.net-mvc-5

Following Error i get it,
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 Consol

You need to perform this commands in Package Manager Consol
Enable-Migrations
Add-Migration "Initial"
Update-Database
There you will have a database with migrations based on your models classes

Related

ASP.NET Core 2.0 Code First Migration - New Database

I currently have an ASP.NET Core 2.0 project and I've just implemented code first migrations to the localdb and have around 3 migrations including the initial create. I'm wondering what the correct process is to change to a new database? Is it simply a case of updating the connection string and running the below in the project directory?
dotnet ef database update
My current knowledge is based on the below Microsoft tutorial and I've been using the CLI commands.
https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations
In answer to my own question, it does appear that running the following command in the existing project directory will build a new database from scratch including all the existing migrations. As long as you update the connection string to the new database and have already implemented migrations on the existing database.
dotnet ef database update
correct process is to change to a new database
Everything depends what you mean by writing this sentence ( I am not sure what "new database" means in it) altough flow looks like this:
1. First you make initial create
2. Then you change something in your code (create some additional fields etc)
3. Then you write "dotnet ef database update" command in CLI to update your current database.

How do you tell entity framework to create / deploy a database in Azure?

I'm using Entity Framework with a code first model; I've got my InitialCreate migration setup and working locally, I can run code against my database context, and everything works.
But when I deploy my project to Azure, I just get a connection string error ("Format of the initialization string does not conform to specification starting at index 0.").
I can't seem to find where in the Publish dialog are the options to create the Azure database. -- Do I have to create the database separately and hook them up manually? -- If so, what exact process should I follow. Does the database need to have contents?
I thought Microsoft was making a big deal that this could all be done in a single deploy step, but that doesn't seem to be the case from my current experience.
When you publish your project in the publish dialog, there is an option for the code first migration in the Settings tab, it will automatically show your data context and it will give you the option to set the remote connection string, and this will add a section in web.config to specify the data context and the Migration class to run during the migration process.
It will also allow you to set if you want to run the code first Migration or not.
You can also take a backup from the dev and clear the data then upload it to Azure SQL DB, this way the code first data context will check at first connection and it will find the code an database the same

broadleaf database tables does not persist after application shutdown

I have been able to run the DemoSite project after changing the in-memory HSQL database to MySql following the instructions given in the broadleaf commerce getting started instructions for changing databases .
Now when I run the Demosite application I find 183 tables get created and populated with data , but this is in existence only during the running of the application . Once the application is shut down only 4 tables remain in the database .
I am using broadleaf demosite version 4.0.0 and MySql Database . The 4 tables which remain after application shut down are named as follows : -
blc_bank_account_payment
blc_credit_card_payment
blc_gift_card_payment
blc_static_asset_strg
I have changed the relevant properties files "hbmddl2.auto" entry value to "update" so that the database tables don't get created and erased for every new run of the application but still have not been able to get rid of this issue .
I have searched a lot also posted to the relevant forums but no answer . SOF is my last resort . Please help .
When you first run DemoSite you might have blPU.hibernate.hbm2ddl.auto=create-drop in your site/src/main/resources/runtime-properties/development.properties file in order to generate database tables.
How you are running the Site/Admin? From ant tomcat target from IDE or deploying war in tomcat outside of IDE.
I hope you have changed blPU.hibernate.hbm2ddl.auto property value to update.
Now if you are running ant tomcat from IDE, after changing the above property first you need to maven install core/site/admin modules before running site/admin.
If you are running from IntellijIDEA when you stop the application it will drop the tables if you have blPU.hibernate.hbm2ddl.auto=create-drop, where as Eclipse will immediately terminates the process without running the drop phase.
The best thing to do is when you start the application first time , after database tables are created and sample data is populated then take backup of the schema. Then change blPU.hibernate.hbm2ddl.auto to update, run maven install. Now start the application.
Hope it helps.

Entity framework migration and seeding specific update

does anyone know how you can seed a specific update using EF 5 migrations? I have existing database, alredy has lookups populated, and am developing some Audit functionality. I have created an AuditType entity and Audit. When I call update-database, I don't want all my seed data from when I first created the database to be re-added. Do I simply have to manuall delete the existing seed data out or can I do something like name a Configuration.cs with the datetime similar to what gets created when I call add-migration?
Thanks
You can run a specific migration by specifying the name of the migration. For example, If you have a migration called MyTuesdayMigration.cs, In the package manager console, you would run this command:
update-database -TargetMigration MyTuesdayMigration
You may need to delete data so you should use -fore
update-database -TargetMigration MigrationName -force

UpgradeLoadTestResultsRepository.sql error to run a load test in VS2012 Ultimate

I am using VS2012 Ultimate to create Load test.after creating Web performance test and Load test projects I am unable to run web Test and also Load test for same projects.it gives the error:
The load test results database could not be opened. Check that the load test results database specified by the connect string for your test controller (or local machine) specifies a database that contains the load test schema and that is currently available.
You can either upgrade this repository using the SQL script UpgradeLoadTestResultsRepository.sql found in the Visual Studio installation, or create a new repository from a controller using TestControllerConfigUI.exe.
I tried to Upgrade the SQL script but was unable to solve the problem.
I solved this problem by changing the property of Load test 'Storage' to 'None' instead of 'Database'
1.First you have to run the sql query shown in the below folder to create the database
http://i.stack.imgur.com/flTXx.png
2.By running that query the data base name LoadTest2010 will be created.
3.Now in visual studio you have to click on manage test controller and there you have to specify the server name and the database name.Then your load test will run fine.
Hope this helpful...
you can follow this tutorial to solve the problem
http://msdn.microsoft.com/en-us/library/ms182600.aspx
running the script loadtestresultsrepository.sql stored in cd n:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
SQL Express: SQLCMD /S localhost\sqlexpress /i loadtestresultsrepository.sql
SQL: You can install the database to any existing SQL server. For example, if you had a SQL server named ContosoServer1 you would use the following command:
SQLCMD /S ContosoServer1 -i loadtestresultsrepository.sql

Resources