[英]c# EF Core Migration code First invalid column
I did several Migrations for my Core-Projekt for SQLite, now i try to switch from SQLite to SQL. 我为SQLite的Core-Projekt做过几次迁移,现在我尝试从SQLite切换到SQL。
unfortunatly i Get a "System.Data.SqlClient.SqlException (0x80131904): invalid columnname1 'columnname1'. invalid columnname2 'columnname2'."-Exception with my existing SQL-Statements. 不幸的是,我得到一个“ System.Data.SqlClient.SqlException(0x80131904):无效的columnname1'columnname1'。无效的columnname2'columnname2'。”-我现有的SQL语句异常。
Using something like 使用类似
migrationBuilder.Sql("INSERT INTO tablename ('columnname1', 'columnname2 ') VALUES ('columnname1value','columnname2value')");
under SQLite it works fine. 在SQLite下,它可以正常工作。
I tried to add the "dbo."-Prefix to the Tablename due to different naming convetions between SQL and SQLite. 由于SQL和SQLite之间的命名竞争不同,我试图将“ dbo。”-前缀添加到表名。 Same Error. 同样的错误。
Due to the statements the defined tables in the script were not created in the DB 由于语句的原因,未在数据库中创建脚本中定义的表
I tried to seperate the SQL-Statements in a Migration after the table creation. 创建表后,我尝试在迁移中分离SQL语句。 The defined tables are created but Same Error. 已创建定义的表,但存在相同错误。
making a seed is not an option because in some migrations i use update or delete statements. 不允许选择种子,因为在某些迁移中,我使用update或delete语句。
What did i wrong with my statement? 我的陈述错了什么? is it a syntax or a logical problem or did i do it wrong all the time and i was lucky that it works under SQLite. 它是语法还是逻辑问题,还是我一直都做错了,我很幸运在SQLite下工作。
Thanks for your answers 谢谢你的回答
For All the Other Guys and Ladys with the same Problem. 对于所有其他遇到相同问题的男女生。 Here my Solution: 这是我的解决方案:
sle1306 got the right Tip. sle1306得到了正确的提示。 Removing the Syntax-Error I change the quotes to brackets. 删除语法错误我将引号更改为方括号。
To get it work with SQLite And MS SQL: expand the genertated Code for SQLite on all Tables 要使其与SQLite和MS SQL一起使用:在所有表上展开生成的SQLite代码
Id = table.Column<int>(nullable: false) .Annotation("Autoincrement", true)
with/to 用/
Id = table.Column<int>(nullable: false) .Annotation("Autoincrement", true).Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
now it works for both of my Databases 现在它适用于我的两个数据库
For All the Other Guys and Ladys with the same Problem. 对于所有其他遇到相同问题的男女生。 Here my Solution: 这是我的解决方案:
sle1306 got the right Tip. sle1306得到了正确的提示。 Removing the Syntax-Error I change the quotes to brackets. 删除语法错误我将引号更改为方括号。
To get it work with SQLite And MS SQL: expand the genertated Code for SQLite on all Tables 要使其与SQLite和MS SQL一起使用:在所有表上展开生成的SQLite代码
Id = table.Column<int>(nullable: false) .Annotation("Autoincrement", true)
with/to 用/
Id = table.Column<int>(nullable: false) .Annotation("Autoincrement", true).Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
now it works for both of my Databases 现在它适用于我的两个数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.