-
Notifications
You must be signed in to change notification settings - Fork 3.3k
NullReferenceException scaffolding when no primary key set #29516
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Which provider? |
MS-sql
|
Thanks, I meant "CREATE" scripts for you database schema (tables, foreign keys) |
im going to try and scaffold each schema seperately, not entirely sure about create scripts, theres about 200+ tables |
@hm2075 Can you also post the full output from running the command with the |
narrowed it down to a table, it didnt have an identity column set ! |
Can you share the CREATE TABLE script for the table causing the issue? |
the table that caused the issue
|
I am confused ... did you mean primary key? |
yes, you are correct , i meant primary key the differences are with exception
without exception
|
Same issue here for a table with no PK's. |
@aldrashan are you able to create a full repro and share it? (Just the CREATE scripts) |
Setting a PK (UserId, RoleId) fixes the problem. |
@aldrashan I think we need scripts for the related tables also |
Added PK solved the problem for me too. This is the query I used to find the table without primary key: select schema_name(tab.schema_id) as [schema_name],
tab.[name] as table_name
from sys.tables tab
left outer join sys.indexes pk
on tab.object_id = pk.object_id
and pk.is_primary_key = 1
where pk.object_id is null
order by schema_name(tab.schema_id),
tab.[name] |
Minimum example to replicate the issue. |
@aldrashan Thanks a lot! |
@bricelam We should consider patching this. |
Note from triage: we should prepare a patch for this. |
🩹 WorkaroundYou can work around this by using custom templates and adding a null check to DbContext.t4 line 219:
|
Using |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
I had the same error on code first with builder.Property(u => u.CurrentUserId).HasColumnType("bigint"); When the table was string see currentuserid public abstract class EntityBase : IEquatable<Entity>
|
upgraded a dotnet app from 6 to 7 with efcore updated to 7
unable to scaffold
dotnet-ef dbcontext scaffold
Entity Framework Core .NET Command-line Tools 7.0.0
The text was updated successfully, but these errors were encountered: