ef-migrations

Entity Framework Core 2.1, rename table using code-first migrations without dropping and creating new table

大兔子大兔子 提交于 2019-12-13 13:12:54
问题 I'm using netcoreapp 2.1 with EF Core 2.1 and updating my database with data migrations and have come into a problem with renaming tables. My main issue here is a table (and later potentially columns) may be renamed multiple times with data and I want to be able to rename them while keeping this data intact but from what I've read it seems these migrations only seem concerned with keeping the schema up to date. This issue is similar to Change or rename a column name without losing data with

EF6 One to Many and Many to One between same entities

♀尐吖头ヾ 提交于 2019-12-13 07:57:27
问题 I'm trying to create a double relationship. Lets say its a Team and Players - a Team has many Players but only one captain public class Team { public int Id { get; set; } public virtual ICollection<Player> Players { get; set; } public Player Captain { get; set; } public int CaptainId { get; set; } } public class Player { public int Id { get; set; } public string Name { get; set; } [InverseProperty("Players")] public virtual Team Team { get; set; } public int TeamId { get; set; } } When

Generate missing migrations so I can update an old database structure

寵の児 提交于 2019-12-13 07:34:01
问题 I am using EF Code first with Migrations. I need to update an old database however I have lost some of the migration code. Is there a way to generate the missing migrations? 回答1: Step 1: Back up ( obviously ) Step 2: Delete __MigrationHistory Step 3: Create a temporary project. Use the Entity Data Model Wizard to create the Code-First Model. Step 4: Enable migrations in the new project ( using Enable-Migrations) at the Package Manager Console. Create an initial migration ( using add-migration

EF Applies All Migrations, Not Just New One

只谈情不闲聊 提交于 2019-12-13 07:22:31
问题 I'm using EF 6 and when I run Update-Database it is trying to apply every migration since the beginning of the project, even though there is only migration that is new. If I attempt to create an empty migration, I get an error that says I can't create a new migration because there are explicit migrations pending. The only blog post I found with a similar issue suggested dropping the __MigrationHistory table and doing Update-Database -Script , stripping out all the actual DB changes but

Where the CREATE DATABASE statement is generated in Entity Framework Code First with Migrations?

只愿长相守 提交于 2019-12-13 07:20:21
问题 I need to configure the database created by Entity Framework Code First MigrateDatabaseToLatestVersion class. Is it possible to influence the database files parameters like size or maxsize? What interests me in particular, is there a way to add database files? I assume I need to find the moment where the Entity Framework generates the CREATE DATABASE statement and influence it a bit. As far as I understand, the SqlServerMigrationSqlGenerator class is too late because the database already

EF 4.3 Code First Migrations - Uncompress __MigrationHistory Model

谁说胖子不能爱 提交于 2019-12-13 06:10:47
问题 How can I uncompress/read the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table? I found a hint in this comment, that I can uncompress it using zip/gzip, but I don't know how exactly I should do this. The problem is that I have changed something in my ef model classes, but when I call "add-migration" an empty migration ist generated. I think that is because the changes of my model classes are already assigned to an existing migration :( 回答1: (this may be a

Possible to add migration using EF DbMigrator

[亡魂溺海] 提交于 2019-12-13 06:07:21
问题 Is it possible to add a migration file using DbMigrator in code instead of through the powershell commands? 回答1: DbMigrator is class for running migrations. Classes for creating migration are in System.Data.Entity.Migrations.Design. ToolingFacade is called by powershell commands. Other classes represents low level API for creating migration code. 来源: https://stackoverflow.com/questions/12353840/possible-to-add-migration-using-ef-dbmigrator

There is already an object named 'AspNetUsers' in the database

陌路散爱 提交于 2019-12-13 02:02:55
问题 I have searched all over the internet, stack overflow but i am feeling lost in the mystery of Entity framework Migration. I have existing database. I have added three new tables which have some relation with AspNetUsers table. I have tried two ways to add these tables to database using pmc. first comment out all new tables in dbcontext and then use following command. Add-migration initial -ignorechanges then uncomment the tables from dbcontext and run update-database command. result no new

EF Code First with existing database on another database

一曲冷凌霜 提交于 2019-12-12 22:51:31
问题 The title is a bit confusing but I'm trying to specify that the problem is not initiating a code first model and migration for an existing database, but comes after that. I needed to activate automatic migration because we switched to a code first model for our system. So, here's what has been done: I created an empty InitialCreate for the existing database I did some other scripts because there were some changes, those worked OK and the scripts were created and run on database The problem

Unable to apply code first migrations to mysql database

霸气de小男生 提交于 2019-12-12 19:23:09
问题 I am working on asp.net mvc with EF code first model. I am trying to apply migrations using EF code first to my project. I am using MySql database. currently i am using EF 4.3.1 version and mysql connector/.net of 6.6.4.0 version. I am successfully add migrations to my project that means i execute series of commands that gave no errors for me. I have followed these steps, PM> Enable-Migrations PM> Add-Migration InitialMigration PM> update-database -verbose these steps create Migration folder