Every Time I try to use ef migrations add came with following error.
PS D:\Development\ItsomaxMonitorDB Preview2 Test\Itsomax.WebHost> dotnet ef migrations add Initial
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:16.53
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'D:\Users\mkowoll\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (26ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
W
ORDER BY "MigrationId";
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
info: Microsoft.EntityFrameworkCore.Migrations[200405]
No migrations were applied. The database is already up to date.
fail: Microsoft.EntityFrameworkCore.Database.Command[200102]
Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "x"."Id", "x"."ConcurrencyStamp", "x"."Name", "x"."NormalizedName"
FROM "Core_Role" AS "x"
WHERE "x"."Name" = 'Admin'
LIMIT 1
Npgsql.PostgresException (0x80004005): 42P01: relation "Core_Role" does not exist
at Npgsql.NpgsqlConnector.<DoReadMessage>d__148.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnector.<ReadMessage>d__147.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlConnector.<ReadMessage>d__147.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnector.<ReadExpecting>d__154`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
@roji can you please check, still having this error after using the latesst package
@MathiasKowoll the latest package only fixed the NpgsqlDesignTimeServices issue, not this one.
I've created a scratch project and managed to successfully generate migrations and apply them to a database, so your case is a specific problem, and more information is needed to understand what's going on. There is likely a problem with a mismatch between the migration and the actual database state - your logs show that EF thinks the database is up to date, but your table is missing. Can you please first confirm that applying your migration(s) on a totally new (i.e. non-existing) database works well? Then, please post your migration(s) etc.
@roji I found the problem. I had an ApplicationBuilder extention where I seed data into the DataBase. when running My app for the first time. For some reason when using EF programs it try to run those queries and inserts even if the database doesn't exists. Removing The seed data in my startup.cs file fixed the problem.
With preview 1 this didn't happen.
Another thing is that database it isn't being create when running dotnet ef database update.
Thanks for support.
@roji, @MathiasKowoll: The problem is in entity framework and not this library.
https://github.com/aspnet/EntityFramework/issues/9076#issuecomment-313463257
The BuildWebHost always calls Configure() so be carefully.
Quick fix for now is to comment whatever you have in Startup.Configure when you are using the tools.
@aghe @roji I have a workaround here I put this code in my custom application builder and get passed all the entity framework commads like migrations add, remove update and drop databases.
var dataBaseExists = context.Database.GetAppliedMigrations().Count();
if (dataBaseExists > 0)
{
do all your databases validations. insert update delete etc.
}
this has been fix by msbuild team, nothing to do with this library. migrations work with no issues on .net core 2.0.0.
But it is a problem in net core 2.1.302
@netfed please open a new issue with a full code sample.
Most helpful comment
@roji, @MathiasKowoll: The problem is in entity framework and not this library.
https://github.com/aspnet/EntityFramework/issues/9076#issuecomment-313463257
The BuildWebHost always calls Configure() so be carefully.
Quick fix for now is to comment whatever you have in Startup.Configure when you are using the tools.