question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core failing when executing migration, containing datetime. Works great with EnsureCreated

See original GitHub issue

I couldn’t find a similar issue, sorry if there is already an answer of that.

So I’m having the following problem:

I’m trying to create a database from scratch using the code first approach and EF Core migrations.

When I’m using: context.Database.EnsureCreated(); it works flawlessly and my database gets created.

The problem is when I try with context.Database.Migrate(); Then I hit an error:

Npgsql.PostgresException: ‘42704: type “datetime” does not exist’

I have some DateTime (C# properties) columns in my entities, but this should not be a problem.

So I’m wondering - why would it work with the first approach, and not with the second one, and is there a solution for this problem?

All kind of help, or guidance appreciated! Thanks!

PS: When I use EnsureCreated() the columns in PostgreSQL db are timestamps (properly translated).

PSS: Here is a SO issue for that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
austindrenskicommented, Aug 3, 2018

@Babalev Great to hear! I’ll go ahead and close this issue.

1reaction
Babalevcommented, Aug 3, 2018

Sure. I’ll wrap up some very minimalist console

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core failing when executing migration, containing ...
I'm trying to create a database from scratch using the code first approach and EF Core migrations. When I'm using: context.Database.
Read more >
Database.EnsureCreated() not creating tables
Basically, I have no idea what happens in that tutorial, or why that solution works. I found out that services aren't built in...
Read more >
Part 4, Razor Pages with EF Core migrations in ASP.NET ...
If a migration is created to remove a column, the ef migrations add command succeeds but the ef database update command fails. The...
Read more >
Applying Migrations - EF Core
A migration may drop a column when the intent was to rename it, or may fail for various reasons when applied to a...
Read more >
Migrating from EF6 to EF Core
Run the application and do manual testing (use another database name than you normally do in dev). If that looks OK it's time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found