英文:
EF Core migrations change name
问题
同事为迁移命名为:“更改扫描对象上的关系”。
这将产生以下输出警告:
21>C:\[REDACTED]\Migrations\Migrations230202123158_changed relatino on scanned objects.cs(8,26,8,57): 警告 CS8981: 类型名称 'changedrelatinoonscannedobjects' 仅包含小写 ASCII 字符。此类名称可能会被语言保留。
21>C:\[REDACTED]\Migrations\Migrations230202123158_changed relatino on scanned objects.Designer.cs(16,19,16,50): 警告 CS8981: 类型名称 'changedrelatinoonscannedobjects' 仅包含小写 ASCII 字符。此类名称可能会被语言保留。
这些迁移已经存在于数据库中。
如何安全地重命名此迁移以抑制警告消息?迁移已经存在于数据库中。
使用.NET7和EF7。
英文:
A colleague named a migration: changed relatino on scanned objects
.
This gives the following output warning:
21>C:\[REDACTED]\Migrations\Migrations230202123158_changed relatino on scanned objects.cs(8,26,8,57): warning CS8981: The type name 'changedrelatinoonscannedobjects' only contains lower-cased ascii characters. Such names may become reserved for the language.
21>C:\[REDACTED]\Migrations\Migrations230202123158_changed relatino on scanned objects.Designer.cs(16,19,16,50): warning CS8981: The type name 'changedrelatinoonscannedobjects' only contains lower-cased ascii characters. Such names may become reserved for the language.
These migrations are already in the database.
How would i go about safely renaming this migration to suppress the warning message? The migration is already in the Db.
Using NET7 with EF7.
答案1
得分: 0
You can rename migration files without being worried about applied migration in DB because EF uses the passing name to MigrationAttribute for MigrationId
. If you open 20230202123158_changed relatino on scanned objects.Designer.cs
class, it should be decorated with the attribute with such an identifier
[Migration("20230202123158_changed_relatino_on_scanned_objects")]
After renaming files you can safely check if there are any pending migration or not?
var appliedMigrations = dbContext.GetService<IHistoryRepository>()
.GetAppliedMigrations()
.Select(m => m.MigrationId);
var total = dbContext.GetService<IMigrationsAssembly>()
.Migrations.Select(m => m.Key);
var hasPendingMigration = total.Except(appliedMigrations).Any();
If there wasn't any update, you're done; otherwise, you should manually update migration id in DB.
英文:
You can rename migration files without being worried about applied migration in DB because EF uses the passing name to MigrationAttribute for MigrationId
. If you open 20230202123158_changed relatino on scanned objects.Designer.cs
class, it should be decorated with the attribute with such a identifier
[Migration("20230202123158_changed_relatino_on_scanned_objects")]
After renaming files you can safely check if there are any pending migration or not?
var appliedMigrations = dbContext.GetService<IHistoryRepository>()
.GetAppliedMigrations()
.Select(m => m.MigrationId);
var total = dbContext.GetService<IMigrationsAssembly>()
.Migrations.Select(m => m.Key);
var hasPendingMigration = total.Except(appliedMigrations).Any();
If there wasn't any update, you're done otherwise you should manually update migration id in DB.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论