Fix PostgreSQL event_type table missing error by replacing EnsureCreated with Migrate#93
Closed
Fix PostgreSQL event_type table missing error by replacing EnsureCreated with Migrate#93
Conversation
…ted with Migrate Co-authored-by: leighghunt <349153+leighghunt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Npgsql.PostgresException (0x80004005): 42P01: relation "event_type" does not exist
Fix PostgreSQL event_type table missing error by replacing EnsureCreated with Migrate
Jul 10, 2025
leighghunt
requested changes
Jul 10, 2025
Member
leighghunt
left a comment
There was a problem hiding this comment.
Can you apply this to the release/zookeeper branch rather than the main branch please?
Author
Applied the same fix to the release/zookeeper branch as requested. The changes are now available in the new branch |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
The application was failing during startup with the following PostgreSQL error:
This error occurred when the database initialization tried to seed EventTypes data but the
event_typestable didn't exist in the database.Root Cause
The
DbInitializer.Initialize()method was usingcontext.Database.EnsureCreated()which bypasses Entity Framework migrations and creates the database schema based only on the current model. This approach:20230807050342_EventTypes.cs)context.EventTypes.Any()Solution
Replaced
EnsureCreated()withMigrate()in/timelapse.api/Data/DbInitializer.cs:Also added the required using directive:
+ using Microsoft.EntityFrameworkCore;Why This Works
Migrate()applies all pending Entity Framework migrations in the correct orderevent_typestable with proper snake_case naming conventionTesting
This ensures that the database schema is properly initialized through migrations before any data seeding occurs, resolving the PostgreSQL table missing error.
Fixes #92.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.