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

Problems with mssql IDENTITY_INSERT #841

Closed
kiwih opened this issue Feb 8, 2016 · 9 comments
Closed

Problems with mssql IDENTITY_INSERT #841

kiwih opened this issue Feb 8, 2016 · 9 comments

Comments

@kiwih
Copy link
Contributor

kiwih commented Feb 8, 2016

With the latest version of gorm, I get the following error appearing when using mssql
Cannot insert explicit value for identity column in table 'collections' when IDENTITY_INSERT is set to OFF.

Is there any chance you could install the free MsSQL from https://www.microsoft.com/en-us/server-cloud/products/sql-server-editions/sql-server-express.aspx and try it out with your test suite?

I suspect the issue is related to #647 and #652

I will try create a small test case for you that fails during use.

@kiwih
Copy link
Contributor Author

kiwih commented Feb 8, 2016

The issue is remarked upon in https://msdn.microsoft.com/en-nz/library/ms188059.aspx
Basically, if an ID is going to be provided by GORM, the transaction must request that identity insert be set to on or else it will be rejected

@jinzhu
Copy link
Member

jinzhu commented Feb 14, 2016

Hello @kiwih

I think you could just Execute SET IDENTITY_INSERT ON after setup database, then it would be ok? If yes, I would update the mssql dialect in the v1.0 release to make it works.

(sorry, I am not on a windows, so can't test it out, it would be really helpful if you could help on that)

@jinzhu jinzhu added this to the v1.0 milestone Feb 14, 2016
@kiwih
Copy link
Contributor Author

kiwih commented Feb 14, 2016

The problem is that you need to set it per table, not database wide, and only one table can have it at a time... Really, it needs to be set per transaction, if the transaction needs it. Does gorm know whether or not it is creating something with an ID before the transaction starts?

Sent from Outlook Mobilehttps://aka.ms/blhgte

@jinzhu
Copy link
Member

jinzhu commented Feb 15, 2016

Sound like this have to be done with overwriting callback. https://github.com/jinzhu/gorm/blob/master/callback_create.go#L117

@jinzhu
Copy link
Member

jinzhu commented Mar 5, 2016

Hi @kiwih

I have pushed some fixes to the v1.0_dev branch to fix this issue, but as I don't have a installed mssql server, could you help test it out?

Let me know if still has any issues.

Thank you.

@jinzhu jinzhu closed this as completed Mar 5, 2016
@kiwih
Copy link
Contributor Author

kiwih commented Mar 7, 2016

I will test it ASAP. Thanks jinzhu!

@jinzhu
Copy link
Member

jinzhu commented Mar 7, 2016

Cool, thank you, just fyi, you need to import the mssql driver with:

import _ "github.com/jinzhu/gorm/dialects/mssql"

@kiwih
Copy link
Contributor Author

kiwih commented Mar 14, 2016

Hi Jinzhu, I am now setting up test environment for gorm (I have been using older commit up to this point). I will run test suite for current version against mssql and post results

@kiwih
Copy link
Contributor Author

kiwih commented Mar 14, 2016

Refer to #908 in future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants