PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How to generate empty migration in Entity Framework Core?

 April 13, 2022     c#, database-migration, entity-framework-core, entity-framework-migrations, migration     No comments   

Issue

I am using EF Core migrations to upgrade my database schema and my data.

As I write new C# code, I need to change the data in my different database environments: development, test, industrialisation, staging and production.

Because I don't want to execute a SQL script in as many environments I have, my goal is to put some data migration in a C# migration. Then the data migration will be executed with the other schemas migrations. Preventing me from forgetting.

How can I create an empty C# migration script to change my data with calling SQL, even if I have no database change?


Solution

Without any changes in data models, when you run the below command, there will be an empty migration file. Then you can put the data manipulation sql code in Up method and revert sql code in Down method :

cli :

dotnet ef migrations add [migrationName]

package manager console :

Add-Migration [migrationName]


Answered By - akash
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing