You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| <nobr>`--dry-run`</nobr> || Show which database would be dropped, but don't drop it. |
137
+
| <nobr>`--connection <CONNECTION>`</nobr> || The connection string to the database. Defaults to the one specified in `AddDbContext` or `OnConfiguring`. Added in EF Core 11. |
137
138
138
139
The [common options](#common-options) are listed above.
139
140
@@ -341,12 +342,17 @@ Removes the last migration, rolling back the code changes that were done for the
| <nobr>`--force`</nobr> | <nobr>`-f`</nobr> | Revert the latest migration, rolling back both code and database changes that were done for the latest migration. Continues to roll back only the code changes if an error occurs while connecting to the database. |
| <nobr>`--force`</nobr> | <nobr>`-f`</nobr> | Revert the latest migration, rolling back both code and database changes that were done for the latest migration. Continues to roll back only the code changes if an error occurs while connecting to the database. |
348
+
| <nobr>`--connection <CONNECTION>`</nobr> || The connection string to the database. Defaults to the one specified in `AddDbContext` or `OnConfiguring`. Added in EF Core 11. |
349
+
| <nobr>`--offline`</nobr> || Remove the migration without connecting to the database. Added in EF Core 11. |
347
350
348
351
The [common options](#common-options) are listed above.
349
352
353
+
> [!NOTE]
354
+
> The `--offline` and `--force` options cannot be used together, since `--force` requires a database connection to check if the migration has been applied before reverting it.
| <nobr>`-WhatIf`</nobr> | Show which database would be dropped, but don't drop it. |
155
+
| <nobr>`-Connection <String>`</nobr> | The connection string to the database. Defaults to the one specified in `AddDbContext` or `OnConfiguring`. Added in EF Core 11. |
155
156
156
157
The [common parameters](#common-parameters) are listed above.
157
158
@@ -210,12 +211,17 @@ Removes the last migration (rolls back the code changes that were done for the m
| <nobr>`-Force`</nobr> | Revert the migration (roll back the changes that were applied to the database). |
217
+
| <nobr>`-Connection <String>`</nobr> | The connection string to the database. Defaults to the one specified in `AddDbContext` or `OnConfiguring`. Added in EF Core 11. |
218
+
| <nobr>`-Offline`</nobr> | Remove the migration without connecting to the database. Added in EF Core 11. |
216
219
217
220
The [common parameters](#common-parameters) are listed above.
218
221
222
+
> [!NOTE]
223
+
> The `-Offline` and `-Force` parameters cannot be used together, since `-Force` requires a database connection to check if the migration has been applied before reverting it.
224
+
219
225
## Scaffold-DbContext
220
226
221
227
Generates code for a `DbContext` and entity types for a database. In order for `Scaffold-DbContext` to generate an entity type, the database table must have a primary key.
### Connection and offline options for migrations remove
201
+
202
+
The `dotnet ef migrations remove` and `database drop` commands now accept `--connection` parameters, allowing you to specify the database connection string directly without needing to configure a default connection in your `DbContext`. Additionally, `migrations remove` supports the new `--offline` option to remove a migration without connecting to the database:
203
+
204
+
```console
205
+
# Remove migration with specific connection
206
+
dotnet ef migrations remove --connection "Server=prod;Database=MyDb;..."
207
+
208
+
# Remove migration without connecting to database (offline mode)
209
+
dotnet ef migrations remove --offline
210
+
211
+
# Revert and remove applied migration
212
+
dotnet ef migrations remove --force
213
+
214
+
# Drop specific database by connection string
215
+
dotnet ef database drop --connection "Server=test;Database=MyDb;..." --force
216
+
```
217
+
218
+
The `--offline` option skips the database connection check entirely, which is useful when the database is inaccessible or when you're certain the migration hasn't been applied. Note that `--offline` and `--force` cannot be used together, since `--force` requires a database connection to check if the migration has been applied before reverting it.
219
+
220
+
In PowerShell, use the `-Connection` and `-Offline` parameters:
0 commit comments