Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non primary key integers are generated as "serial" #37

Closed
m-ghaoui opened this issue May 21, 2016 · 4 comments
Closed

Non primary key integers are generated as "serial" #37

m-ghaoui opened this issue May 21, 2016 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@m-ghaoui
Copy link

m-ghaoui commented May 21, 2016

I have a model that looks like this:

public int Images_Large { get; set; }

And it has a default value defined in the OnModelCreating of a DbContext

entity.Property(e => e.Images_Large).HasDefaultValueSql("250");

The above code was generated by scaffolding an existing PostgresSQL database. I don't think it matters if you use HasDefaultValueSql("250") or HasDefaultValue(250).

When you try to update a PostgresSQL database, you get this error:

42601: multiple default values specified for column "Images_Large" of table "MyTable"

I generated a script using dotnet ef migrations script -o First.sql and loaded it in pgadmin3. The column was scaffolded as such:

"Images_Large" serial NOT NULL DEFAULT (250),

The "Images_Large" column is not the primary key of the database and therefore should not be mapped as serial. I changed the script to:

"Images_Large" integer NOT NULL DEFAULT (250),

And it's fixed.

This also happens to short and byte too.

@roji roji added the bug Something isn't working label May 22, 2016
@roji roji added this to the 1.0.0-rc2-release2 milestone May 22, 2016
@roji roji self-assigned this May 22, 2016
@roji
Copy link
Member

roji commented May 22, 2016

@Yuioup I'll take a look, but can you please post the full model definition, not just the field?

@roji
Copy link
Member

roji commented May 22, 2016

@Yuioup it's OK, I think I understand what's going on (full model not needed).

@m-ghaoui
Copy link
Author

Ok cool :-)

@roji roji closed this as completed in 85fa98e May 23, 2016
@m-ghaoui
Copy link
Author

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants