Open kjartanium opened 5 months ago
Hmm, I'm assuming this happens because the connection string isn't really created at that point since the services isn't fired up. I guess i need to do it runtime, or are there any other workarounds?
This is because the connection string isn't available when you run from the command line. It's possible to run some dotnet ef commands without a valid connection string (a dummy one is still required), but dotnet ef database update
isn't possible to run without the database running and the connection string being available in the application.
Possible workarounds;
Run the apphost, get the connection string from the dashboard (look at the environment variables of the application), and use it to run dotnet ef database update
(passing in the connection string)
Nice workaround, thanks for the tip! For me it worked only after adding --no-build
option, because running the app locks some files that need to be updated during build.
Using GA version.
Create a .NET Aspire Starter project in VS
Add packages in Api service project:
Create a DbContext in the api service
Create a migration in the Api service using "dotnet ef migrations add initial"
Update the migration in the database fails with the following:
Build started... Build succeeded. System.ArgumentException: Host can't be null at Npgsql.NpgsqlConnectionStringBuilder.PostProcessAndValidate() at Npgsql.NpgsqlConnection.SetupDataSource() at Npgsql.NpgsqlConnection.set_ConnectionString(String value) at Npgsql.NpgsqlConnection..ctor(String connectionString) at Npgsql.NpgsqlConnection.CloneWith(String connectionString) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlRelationalConnection.CloneWith(String connectionString) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists() at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists() at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations() at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Host can't be null
I've tried with all possible locations of the migration assembly and so forth, same error.