Skip to content

How does one check that a database contains the schema for the current model? #37707

@SolalPirelli

Description

@SolalPirelli

Question

Some low-level APIs explicitly call out that they perform no schema validation, such as DatabaseFacade.EnsureCreated:

If the database exists and has any tables, then no action is taken. Nothing is done to ensure the database schema is compatible with the Entity Framework model.

As well as HasTables and Exists on IRelationalDatabaseCreator:

No attempt is made to determine if tables belong to the current model or not.

Such wording implies there should be a way to validate that a database conforms to the current schema, but I couldn't find how to do that. Is checking for the absence of pending migrations enough?

For context, my use case is that I have a website using a SQLite database, and I want to let users export and import backups of the entire database as a file. Before overwriting the local database with a user-provided backup, I'd like to check that said backup actually did come from the system rather than the user accidentally uploading the wrong file and destroying everything.

Your code

Stack traces


Verbose output


EF Core version

10.0.3

Database provider

Microsoft.EntityFrameworkCore.Sqlite

Target framework

.NET 10

Operating system

Windows 11

IDE

VS 2026

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions