0

After downloading the latest version, I run the migration command:
update-database.

Then I started the Host project, which throws an exception:

"Field 'Id' doesn't have a default value "

Took a look in the tables that the migration script generated, I noticed that all the Id columns were not set "Auto Increment" property while you did not set Id value for seeding values.
That's why when we seed some initial values into DB it throws the errors.

Any ideas? Please help me to solve the problem

buydadip
  • 8,890
  • 22
  • 79
  • 154
  • Thank you for your attention. I resolved the problem by editing the Migration files under Migrations folder. I changed the ValueGenerationStrategy in those file from SqlServer to MySql and it worked properly! – Hung Nguyen Mar 18 '19 at 03:02
  • I’m voting to close this question because while similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. – aaron Sep 18 '21 at 04:39

1 Answers1

0

I had the same problem.

In Migration file I edited the line

Id = table.Column<int>(type: "int", nullable: false)

To:

Id = table.Column<int>(type: "int", nullable: false).Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),

Ps.: I am using MariaDB Database