简体   繁体   English

传统表使SQL Server的映射问题失败

[英]Legacy tables grails mapping issue with SQL Server

I have 2 legacy tables into SQL Server: 我在SQL Server中有2个旧表:

An these are my domain classes for these tables 这些是这些表的域类

When I try to insert a Taladro into the database using the dinamic scaffolding fails with these error: 当我尝试使用动态脚手架将Taladro插入数据库时​​,由于以下错误而失败:

ERROR util.JDBCExceptionReporter - Cannot insert the value NULL into column 'proyecto_id', table 'Portal.ORECONTROL.TALADROS'; 错误util.JDBCExceptionReporter-无法将值NULL插入表'Portal.ORECONTROL.TALADROS'的列'proyecto_id'中; column does not allow nulls. 列不允许为空。 INSERT fails. INSERT失败。

I change the name of the foreign key from id_proyecto to IdMalla as are in the legacy tables (See http://ur1.ca/hl1mw ). 我将旧键的名称从id_proyecto更改为IdMalla,就像在旧表中一样(请参见http://ur1.ca/hl1mw )。

I'm using a SQL Server 2008 as Database server 我正在使用SQL Server 2008作为数据库服务器

Seems that now you have column proyecto_id in TALADROS table with not-null constraint. 看来,现在你有列proyecto_idTALADROS表非空约束。 In domain object Taladro you have specified association column mapping as 'IdMalla' instead of default 'proyecto_id' . 在域对象Taladro您已将关联列映射指定为'IdMalla'而不是默认的'proyecto_id' Obviously that means that column proyecto_id is not filled and since it has not-null constraint, you get this error. 显然,这意味着未填充proyecto_id列,并且由于它具有非null约束,因此会出现此错误。

I can resolve the problem renaming the domain classes with name of the tables in the database and changing the name of the foreign key to "IdMalla". 我可以解决使用数据库中表的名称重命名域类并将外键的名称更改为“ IdMalla”的问题。 Thanks all for the answers 谢谢大家的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM