-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Scaffold-DbContext not correctly configuring auto incrementing primary key in from Sqlite database #11961
Comments
Possibly related, also in SQLite. I found out that with my entity: public class Account
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Balance { get; set; }
} giving modelBuilder.Entity<Account>()
.Property(ac => ac.Balance)
.HasDefaultValue(1500); scaffolds the following in a migration: migrationBuilder.CreateTable(
name: "Accounts",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Balance = table.Column<int>(nullable: false, defaultValue: 1500)
.Annotation("Sqlite:Autoincrement", true) //WTF?
}); Why does the scaffolding think that the second column needs auto-increment? Commenting out the bit in |
I have the same problem with GUID. |
Ran into the same issue with EFCore 2.1.2
renders a PRIMARY KEY AUTOINCREMENT field as a ValueGeneratedNever in the generated DbContext, and the reverse operation
generates PRIMARY KEY AUTOINCREMENT columns in the SQLite db where the property either has no ValueGenerated... at all, or is explicitly ValueGeneratedNever(). Looking forward to 2.2.0 I guess. |
Still no fixes for this |
Any updates on this? |
Willing to take a PR for this? |
I'm using EF.Core scaffold to create a datamodel for a DB with an auto increment primary key but the context is being generated with the key annotated with ValueGeneratedNever() instead of ValueGeneratedOnAdd(). As a result EF framework requires each record to have a primary key set instead of allowing the DB to set it.
Steps to reproduce
Create an SQLite DB with this table:
In the package manager console run:
Examine the context class, it generates with:
ValueGeneratedNever() should be ValueGeneratedOnAdd()
Further technical details
EF Core version: (found in project.csproj or packages.config) 2.1.0-rc1-final (also happens in 2.0.2)
Database Provider: (e.g. Microsoft.EntityFrameworkCore.Sqlite)
Operating system: Win 10 1709
IDE: (e.g. Visual Studio 2017 15.6.3)
The text was updated successfully, but these errors were encountered: