admin管理员组文章数量:1346292
I am creating a new project using .NET 9 with Entity Framework Core and Oracle 19c as the database. I have added Identity 9 and when I generated the initial migration it created the tables with NVARCHAR(450)
datatype for any column that is a guid.
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "NVARCHAR2(450)", nullable: false),
Name = table.Column<string>(type: "NVARCHAR2(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "NVARCHAR2(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "NVARCHAR2(2000)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
This script was generated using:
add-migration AddIdentity
which auto-generated it in Visual Studio 2022.
The next thing I did was to extend the IdentityUser
class to include some common attributes like first name and last name for the user.
When I generated the new migration for these extended attributes it changed the data type of each column storing a guid to a RAW(16)
migrationBuilder.AlterColumn<Guid>(
name: "Id",
table: "AspNetUsers",
type: "RAW(16)",
nullable: false,
oldClrType: typeof(string),
oldType: "NVARCHAR2(450)");
Do I need to strip these statements out or be concerned? Seems odd that the original script produced by VS2022 would do it one way and then with the next migration change the data types. Any help or advice would be appreciated.
EDIT --- I just attempted to execute the migration to update the DB. It does not appear to like creating a RAW(16) within the Oracle DB.
Applying migration '20250402143035_ExtendIdentityUser'.
fail: Microsoft.EntityFrameworkCore.Database.Command[0]
2025-04-02 22:33:03.095313 ThreadID:1 (ERROR) OracleRelationalCommand.ExecuteNonQuery() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
2025-04-02 22:33:03.095313 ThreadID:1 (ERROR) OracleRelationalCommand.ExecuteNonQuery() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (169ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
declare
l_nullable user_tab_columns.nullable % type;
begin
select nullable into l_nullable
from user_tab_columns
where table_name = 'AspNetUserTokens'
and column_name = 'UserId'
;
if l_nullable = 'N' then
EXECUTE IMMEDIATE 'ALTER TABLE "AspNetUserTokens" MODIFY "UserId" RAW(16) ';
else
EXECUTE IMMEDIATE 'ALTER TABLE "AspNetUserTokens" MODIFY "UserId" RAW(16) NOT NULL';
end if;
end;
Failed executing DbCommand (169ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
declare
l_nullable user_tab_columns.nullable % type;
begin
select nullable into l_nullable
from user_tab_columns
where table_name = 'AspNetUserTokens'
and column_name = 'UserId'
;
if l_nullable = 'N' then
EXECUTE IMMEDIATE 'ALTER TABLE "AspNetUserTokens" MODIFY "UserId" RAW(16) ';
else
EXECUTE IMMEDIATE 'ALTER TABLE "AspNetUserTokens" MODIFY "UserId" RAW(16) NOT NULL';
end if;
end;
fail: Microsoft.EntityFrameworkCore.Infrastructure[0]
2025-04-02 22:33:03.106263 ThreadID:1 (ERROR) OracleExecutionStrategy.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.Execute(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean beginTransaction, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.<>c.<ExecuteNonQuery>b__3_1(DbContext _, ValueTuple`6 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
2025-04-02 22:33:03.106263 ThreadID:1 (ERROR) OracleExecutionStrategy.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.Execute(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean beginTransaction, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.<>c.<ExecuteNonQuery>b__3_1(DbContext _, ValueTuple`6 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
fail: Microsoft.EntityFrameworkCore.Infrastructure[0]
2025-04-02 22:33:03.107582 ThreadID:1 (ERROR) OracleExecutionStrategy.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.Execute(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean beginTransaction, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.<>c.<ExecuteNonQuery>b__3_1(DbContext _, ValueTuple`6 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateImplementation(DbContext context, String targetMigration, MigrationExecutionState state, Boolean useTransaction)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c.<Migrate>b__20_1(DbContext c, ValueTuple`4 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
2025-04-02 22:33:03.107582 ThreadID:1 (ERROR) OracleExecutionStrategy.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.Execute(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean beginTransaction, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.<>c.<ExecuteNonQuery>b__3_1(DbContext _, ValueTuple`6 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateImplementation(DbContext context, String targetMigration, MigrationExecutionState state, Boolean useTransaction)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c.<Migrate>b__20_1(DbContext c, ValueTuple`4 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
/
at OracleInternal.ServiceObjects.OracleFailoverMgrImpl.OnError(OracleConnection connection, CallHistoryRecord chr, Object mi, Exception ex, Boolean bTopLevelCall, Boolean& bCanRecordNewCall)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.Execute(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean beginTransaction, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.<>c.<ExecuteNonQuery>b__3_1(DbContext _, ValueTuple`6 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IReadOnlyList`1 migrationCommands, IRelationalConnection connection, MigrationExecutionState executionState, Boolean commitTransaction, Nullable`1 isolationLevel)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateImplementation(DbContext context, String targetMigration, MigrationExecutionState state, Boolean useTransaction)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c.<Migrate>b__20_1(DbContext c, ValueTuple`4 s)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.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)
ORA-02267: column type incompatible with referenced column type
ORA-06512: at line 10
This makes be believe that the code to generate the original Identity schema has more awareness of valid data types within Oracle than the engine that generates the migrations as you make modifications. Any ideas or should I just remove the alter statements from the migration?
本文标签: cIdentity Id data type in OracleStack Overflow
版权声明:本文标题:c# - Identity Id data type in Oracle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743827109a2545843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论