Skip to content

Azure Functions v4 "No migrations were applied. The database is already up to date." #27081

@dochoss

Description

@dochoss

I set up my models and got everything ready to go for EF Core in an Azure Functions v4 project. I used the workaround mentioned in this article: https://dev.to/azure/using-entity-framework-with-azure-functions-50aa (copying the project .dll to the root) and was able to get the project to build just fine, and I was able to add the initial migration, which looks correct. When I run Update-Database the __EFMigrationsHistory table is created, but it is empty and none of my tables are present. Update-Database -Verbose result is posted below.

The context is in the functions project, so no reference issues.

EDIT: forgot to mention, I've tried deleting the migrations and starting over (this is just the initial migration, so no worries about that), and dropping the database and/or the EFMigrationsHistory table. Even if the database is dropped, when I try to update, it gives the same result: no migrations were applied.

PM> update-database -Verbose
Using project 'ScholarAPI'.
Using startup project 'ScholarAPI'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\bin\Debug\net6.0\ScholarAPI.deps.json --additionalprobingpath C:\Users\bo\.nuget\packages --runtimeconfig C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\bin\Debug\net6.0\ScholarAPI.runtimeconfig.json C:\Users\bo\.nuget\packages\microsoft.entityframeworkcore.tools\6.0.1\tools\netcoreapp2.0\any\ef.dll database update --verbose --no-color --prefix-output --assembly C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\bin\Debug\net6.0\ScholarAPI.dll --project C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\ScholarAPI.csproj --startup-assembly C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\bin\Debug\net6.0\ScholarAPI.dll --startup-project C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\ScholarAPI.csproj --project-dir C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\ --language C# --configuration Debug --working-dir C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI --root-namespace Scholar.API
Using assembly 'ScholarAPI'.
Using startup assembly 'ScholarAPI'.
Using application base 'C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\bin\Debug\net6.0'.
Using working directory 'C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI'.
Using root namespace 'Scholar.API'.
Using project directory 'C:\Users\bo\Source\Repos\Scholar\api\ScholarAPI\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Found IDesignTimeDbContextFactory implementation 'ScholarContextFactory'.
Found DbContext 'ScholarContext'.
Finding application service provider in assembly 'ScholarAPI'...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Using DbContext factory 'ScholarContextFactory'.
Using context 'ScholarContext'.
Finding design-time services referenced by assembly 'ScholarAPI'...
Finding design-time services referenced by assembly 'ScholarAPI'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'ScholarAPI'...
No design-time services were found.
Migrating using database 'Scholar' on server 'localhost,1433'.
Opening connection to database 'Scholar' on server 'localhost,1433'.
Opened connection to database 'Scholar' on server 'localhost,1433'.
Creating DbCommand for 'ExecuteNonQuery'.
Created DbCommand for 'ExecuteNonQuery' (3ms).
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Executed DbCommand (18ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Closing connection to database 'Scholar' on server 'localhost,1433'.
Closed connection to database 'Scholar' on server 'localhost,1433'.
Creating DbCommand for 'ExecuteScalar'.
Created DbCommand for 'ExecuteScalar' (0ms).
Opening connection to database 'Scholar' on server 'localhost,1433'.
Opened connection to database 'Scholar' on server 'localhost,1433'.
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Executed DbCommand (12ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Closing connection to database 'Scholar' on server 'localhost,1433'.
Closed connection to database 'Scholar' on server 'localhost,1433'.
Opening connection to database 'Scholar' on server 'localhost,1433'.
Opened connection to database 'Scholar' on server 'localhost,1433'.
Creating DbCommand for 'ExecuteNonQuery'.
Created DbCommand for 'ExecuteNonQuery' (0ms).
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Closing connection to database 'Scholar' on server 'localhost,1433'.
Closed connection to database 'Scholar' on server 'localhost,1433'.
Creating DbCommand for 'ExecuteScalar'.
Created DbCommand for 'ExecuteScalar' (0ms).
Opening connection to database 'Scholar' on server 'localhost,1433'.
Opened connection to database 'Scholar' on server 'localhost,1433'.
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Closing connection to database 'Scholar' on server 'localhost,1433'.
Closed connection to database 'Scholar' on server 'localhost,1433'.
Creating DbCommand for 'ExecuteReader'.
Created DbCommand for 'ExecuteReader' (0ms).
Opening connection to database 'Scholar' on server 'localhost,1433'.
Opened connection to database 'Scholar' on server 'localhost,1433'.
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
A data reader was disposed.
Closing connection to database 'Scholar' on server 'localhost,1433'.
Closed connection to database 'Scholar' on server 'localhost,1433'.
No migrations were found in assembly 'ScholarAPI'.
No migrations were applied. The database is already up to date.
'ScholarContext' disposed.
Done.
PM> 

Include provider and version information

EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: net6.0
Operating system: Windows 10
IDE: Visual Studio 2022 17.0.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions