question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IsRequired(false) created same field name with additional 1

See original GitHub issue
public class Table1
{
        public int Table1Id { get; set; }
        public string Name { get; set; }

        public virtual ICollection<Table2> MyTables { get; set; }
}

public class Table2
{
        public int Table2Id { get; set; }
        public int Table1Id { get; set; }
        [ForeignKey("Table1Id")]
        public virtual Table1 Table1 { get; set; }
}

protected override void OnModelCreating(ModelBuilder builder)
{
    builder.Entity<Table1>()
        .HasMany(e => e.MyTables)
        .WithOne(e => e.Table1)
        .IsRequired(false);
}

PostgresException: 42703: column t.Table1Id1 does not exist

The above code generated additional field that is invalid. Removing false in IsRequired() will operate normally. I am currently using Npgsql.EntityFrameworkCore.PostgreSQL v2.1.1.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ajcvickerscommented, Jul 13, 2018

It seems unlikely to me that this would be intentional, so a warning makes sense to me.

1reaction
divegacommented, Jul 13, 2018

I get that there is a compromise, but to me this one seems to be on the border of being invalid configuration. Do you think the chances that anyone would do this on purpose are high? I don’t, but maybe I am missing something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IsRequired(false) created same field name with additional 1
The above code generated additional field that is invalid. Removing false in IsRequired() will operate normally. I am currently using Npgsql.
Read more >
how do i make IsRequired field to false to in mvc?
I have one project in mvc. i have employee model file with me that's is an dll file code. which defines all the...
Read more >
One-to-one relationships - EF Core
One -to-one relationships are used when one entity is associated with at most one other entity. For example, a Blog has one BlogHeader ......
Read more >
Form fields
If a Field has required=False and you pass clean() an empty value, then clean() will return a normalized empty value rather than raising...
Read more >
dataclasses — Data Classes — Python 3.11.4 documentation
One possible reason to set hash=False but compare=True would be if a field is expensive to compute a hash value for, that field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found