Questions tagged [entity-framework-migrations]
Migrations is a feature of Entity Framework that provides for detecting changes to a code(or database)-first model, and upgrading the database (or the model) schema based on those changes.
3,221
questions
0
votes
0
answers
33
views
System.NullReferenceException error when trying to update the database using EF Core [duplicate]
I am making an e-commerce app to try and learn .NET 7. I set up the models and database connection the first time and everything worked great. After I continued to develop the back-end, I added ...
0
votes
1
answer
45
views
Entity Framework error - Either the parameter @objname is ambiguous or the claimed @objtype (Index) is wrong
I am trying to delete few existing columns of 2 tables using code first approach, when I am running the command
update-database -Verbose
in the Nuget package manager console I get the exception ...
0
votes
0
answers
44
views
Is it possible to have an auto-generated string uniqueidentifier that auto-populates when entering data in SSMS?
I've converted a primary int Id key to a string (nvarchar(450), however I want to have it autogenerate new IDs (Guid "Style" but string-formatted, which seems to be the way ASP.NET Core sets ...
0
votes
0
answers
12
views
Seed entity using sql script .net core
I’m having problem right now, I have 2 databases where db A works as repository (we bring data from there and not mapped with EF) and db B (this mapped with EF)
Now we need to create a new entity on ...
1
vote
0
answers
14
views
Check for the migration in ASP.NET MVC framework
enter image description here
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider.
Error: Failed to load configuration from ...
0
votes
1
answer
108
views
How do I generate migrations for an existing database in .NET 6?
Can I start with a database-first approach, generate a migration script from it, and then switch to a code-first approach to maintain synchronization between the code and database in .NET 6, using ...
0
votes
0
answers
26
views
EF migration script generation fails in Azure DevOps with exit code 2147516545
I use the below command to generate the db migration script for my EF Context.
dotnet-ef migrations script --idempotent --output db-migrations.sql --no-build --verbose
This works fine locally, but on ...
0
votes
0
answers
39
views
How to seed data for entity with navigation property in EF Core?
I'm working with EF Core and I have a Role entity that owns a list of RolePermission. I'm using the IEntityTypeConfiguration<Role> interface to configure the entity.
While I am able to seed the ...
0
votes
1
answer
12
views
how to apply add-migration and update-database command in webapi when it shows some error?
I am trying to add-migration with the name Initial and when i update the database it shows some error, so how can i resolve that error.
enter image description here
Introducing FOREIGN KEY constraint '...
-1
votes
0
answers
27
views
Ef migrations - fill table from other database
I’m currently applying migrations to my project, but this time we need to bring data from a MSSQL database and fill one table in the new table that is hosted on PostgreSQL, I already have the query to ...
0
votes
0
answers
24
views
EF Core migration issue with a jsonb column
I have a project that has a Contact entity like this
public class Contact
{
public List<PhoneContact> Phones { get; set; }
}
public class PhoneContact
{
public string Title { get; set; }...
1
vote
0
answers
41
views
Entity Framework Core upgrade from 2.1.4 to 5.0.5 or 6.0.* migration add error Unable to cast object of type 'System.Int32' to type 'System.Int64'
Have confirmed I have not made any db changes or model changes before the upgrade from ef core 2.1.4 to latests version 5 or 6. Yet I seems to now have this error during add migration.
Unable to cast ...
3
votes
1
answer
36
views
One-to-one with two independent tables
I have two tables: Indivdiual and Instructor. If an Instructor is an Individaul (that we track), I want to link their Instructor record to their Individual record. An Individual may or not be an ...
2
votes
1
answer
33
views
Unable to execute "dotnet ef migrations add init" when OnConfiguring() defined in partial class
Here are the steps to reproduce the problem I met:
Clone my code
git clone https://github.com/doggy8088/EFCore7UnableDoMigration.git
cd EFCore7UnableDoMigration
Do the migration
dotnet ef migrations ...
0
votes
0
answers
33
views
EF Core migration to Postgres database "relation" already exists
I have a situation where the database and tables were already created before I brought in EF migrations, which is added to the program.cs like so:
var app = builder.Build();
await app.MigrateDatabase()...
0
votes
2
answers
23
views
Why is migration thinking an entry exist on a recently created table?
I am currently trying to add an message column to my table which is modelled to look like this
public class Notification
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
public ...
1
vote
1
answer
55
views
How do I prevent Entity Framework Core 7 from adding a foreign key field to a certain class referring to that same class, when creating a migration?
Thanks for reading this. I am kind of new to Entity Framework Core, and I am trying to use the code first principle to create migrations that should create my database.
But I stumble upon some ...
0
votes
2
answers
56
views
Why am I not allowed to perform this migration?
I have a postgres database where I use ef to control my migrations code first.
I currently have this table/class.
public class Notification
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid()...
0
votes
2
answers
75
views
Entity Framework, when I run enable-migrations, it doesn't create folder
I am getting errors as shown in this screenshot:
Also I examine my nuget package (for version), Entity Framework packages too.
I asked chatgpt for help, and I did what it want, but it doesn't work.
...
0
votes
0
answers
31
views
Entity Framework Core not detecting changes in model when adding migration
I'm working on a .NET Core project using Entity Framework Core for database operations. I have two entities, Course and Subcategory, with a one-to-many relationship between them. I've added a ...
0
votes
1
answer
41
views
Entity Framework migration in Azure function app with non hardcoded db connction string
I got an Azure function app which works with EF and I want to do a db migration.
The code for the db context has this part:
protected override void OnConfiguring(DbContextOptionsBuilder options)
...
0
votes
0
answers
18
views
EF Migrations on Generic Repository
I´m creating a generic Repository with Entity Framework. It looks like this:
public abstract class EntityRepository<TEntity> : IEntityRepository<TEntity> where TEntity : Entity
{
...
0
votes
0
answers
35
views
Entity Framework Core (6.0.20) migrations not adding primary key to DB
I have a Entity Framework Core 6.0.20 that I use in a code first manner to manage the DB schema of my application.
For some reason, all of my [Key] data annotations are being ignored. It is happening ...
0
votes
1
answer
66
views
What is the proper approach to do a migration squash in .NET Core?
In our solution, C# files generated by .NET Core migrations became 69% of all lines of code which is hurting compile times and intelligence works only on computers with 64+ GM RAM,
so we need to ...
0
votes
0
answers
75
views
How to solve this problem in Entity Framework migration?
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider.
Error: Unable to build IHost
System.ArgumentException: Format of the ...
1
vote
0
answers
25
views
Changing discriminator value produces empty migration
I attempt to rollback using custom Discriminator in TPH hierarchy and start using default ones.
I removed builder.HasDiscriminator().HasValue("CustomValue"); from all the entities ...
1
vote
1
answer
27
views
How to group migrations by year/version?
I realized that with time there is more and more migrations in migration folder. So I want to group those migration by year, application version, feature. For example there could be folders:
...
1
vote
1
answer
1k
views
InvalidDataAccessApiUsageException: Can't compare test expression of type [Facility] with element of type [basicType@4(java.lang.Integer,4)]]
[dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessApiUsageException: Can't compare test expression of type [Facility] ...
0
votes
0
answers
9
views
Visual Studio migration giving a "No suitable constructor" error for linestring in NetTopologySuite
I am attempting to create a migration for my Node class which contains a Polygon from the NetTopologySuite. The error it gives is "No suitable constructor was found for entity type 'LineString'.
...
0
votes
1
answer
54
views
Format of the initialization string does not conform to specification starting at index 0. when Update-Database in ASP.NET Core 6
I have successfully created a migration, but no matter what I do, I can't update the database and the problem seems to be in the connection string.
appsettings.json:
{
"AllowedHosts": &...
0
votes
0
answers
35
views
Moving EF Core Models and Migrations to a new Solution
I've been working on ASP.NET Web API project that was using EF Core Code-First Approach.
Now functionality of this API is being merged with another API, so I need to move that code to a new solution. ...
0
votes
2
answers
77
views
Problem to add-migration using Package Manager Console
I am facing the following issue regarding add-migration using Package Manager Console:
PM> add-migration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following ...
0
votes
1
answer
35
views
Both 'Add-Migration' and 'Install-Package' are not recognised as an internal or external command. Microsoft.EntityFrameworkCore.Tools is installed
Trying to run an initial migration on an .NET 7 ASP.NET API project, but receiving the error
'add-migration' is not recognized as an internal or external command
I have seen several similar threads ...
0
votes
1
answer
45
views
Dotnet EF migrations add is not working in mediatoR pattern
I am working on one project in which is following mediatoR design pattern. Database SQL and it is a code first approach. I have 4 layers
Web.UI
Application
Infrastructure
Domain
Web.UI layer has ...
0
votes
0
answers
17
views
Code First EF - Many-to-Many Relationship Among Properties in An Entity
I'm trying to create a mock social media app, and my goal currently is to keep track of followers and followings for each entity called ForumProfile. I created ICollection properties of 'followers' ...
0
votes
1
answer
114
views
Why does Entity Framework Migration not read file App.xaml.cs in WinUI 3?
I have a WinUI 3 project using GenericHost (based on the default WinUI 3 Visual Studio template):
Host = Microsoft.Extensions.Hosting.Host.
CreateDefaultBuilder().
UseContentRoot(AppContext....
0
votes
0
answers
84
views
Format of the initialization string does not conform to specification
I have a problem using the command line dotnet ef database update. Before it I call migrations with dotnet ef migrations add InitialCreate -o Data/Migrations and it works.
storeContext.cs
using System;...
0
votes
1
answer
34
views
Record the date when EF migration was applied
I have a Code-First Entity Framework context and I'm going to update database using Entity Framework migrations mechanism. For my particular application I need to be able to tell when particular ...
2
votes
2
answers
99
views
How can I run dotnet CLI commands inside a running container?
I have a running container called tami-app. The Dockerfile is based on a .NET 5 SDK:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /Tami.Operations.Api
COPY src/Tami.Operations.Domain/Tami....
2
votes
0
answers
128
views
Circular dependency creating EF migration in MAUI Blazor
Previous research
This is NOT a duplicate of Running dotnet ef migrations for class library gives error MSB4006 - because Microsoft.EntityFrameworkCore.Tools is installed
I have tried several ...
0
votes
0
answers
57
views
The ConnectionString property has not been initialized, while running Database-Update Command
I am getting this error while running the "Update-Database" command in Package Manager Console. I am working on a project with Three Tier Structure. In which I have Three Projects other than ...
0
votes
0
answers
43
views
Data annotation Required in Entity Framework Core with MySQL seems to work incorrectly
In my project, I have a table:
[Table("users")]
public class User
{
[Column("id"), Key, Required]
public int Id { get; set; }
[Column("name"), MaxLength(64)]
...
0
votes
1
answer
66
views
EF migration seeding enum to one migrationBuilder.InsertData
I have an enum type FooNames and I am trying to seed a database table Foo from the enum values. There is an entity type Foo that corresponds to the table Foo.
class Foo
{
[Key]
[Index("pk&...
0
votes
1
answer
132
views
Entity Framework Core UseTpcMappingStrategy() - How to make each table have its own identity?
I'm writing a code-first database project and I'm using UseTpcMappingStrategy() to create table from inherited classes.
I wanted to have several tables with own identity not shared between all of ...
0
votes
0
answers
121
views
EF Core 7 migration Error: Object reference not set to an instance of an object
Using VS22 as IDE, EF Core(Ver. 7.0.5) as an ORM and LocalDB with a code first approach, when trying to create a migration via:
dotnet ef migrations add Test
I get the following output:
Build ...
0
votes
1
answer
43
views
dotnet ef database update works locally but not on Azure VM
I have an orchestration script that copies our legacy app's database to our new app database name in our dev environment, clones our Azure repository (GIT) for our new app and then runs the ef ...
1
vote
2
answers
117
views
Entity Framework is not creating Tables in the Database on Migrate() method call
I am working on a Blazor Server App. I also use Entity Framework. The targeted framework is .NET 7.0. I do have a Postgresql database. Now I have created GameModel:
using System.ComponentModel....
1
vote
2
answers
419
views
How can I set up automatic migrations in Entity Framework Core 7 for my ASP.NET Core MVC web app project?
I created an ASP.NET Core 7.0 MVC web app project. I added Entity Framework Core (v7.0.5) package from NuGet Package Manager.
How do I enable the automatic migrations for my code first project?
In the ...
0
votes
0
answers
26
views
Creating UserDefined Table type using (A) SQL Scripts VS (B) Creating Class in EF Migrations
We are using .NET Core and Entity Framework Core in our project.
I Need to create a User Defined Table Type which will be used as Input by a Stored Procedure.
One way is to add Migration file ...
1
vote
0
answers
84
views
How do I fix this migration error message in Ruby(Sinatra)
I'm new to programming in ruby, started using Sinatra framework and while trying to develop a simple MVC application I tried to create a migration on my Terminal but I'm getting these error messages
...