Hello,
I'm working on developing a Drupal module. I created an update to a table that involves dropping and re-creating a primary key. The update works fine on my local development machine, which is running MySQL. However, when I apply the update to our QA server, which is running SQL Server, the update fails on the db_drop_primary_key() function call. In particular, I am getting the following error:
Failed: PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot define PRIMARY KEY constraint on nullable column in table 'demo_table'.: ALTER TABLE [{demo_table}] ADD CONSTRAINT {demo_table}_pkey_technical PRIMARY KEY CLUSTERED (__pk); Array ( ) in db_drop_primary_key() (line 2869 of C:\inetpub\islandoratest\acquia-drupal7\includes\database\database.inc)
I've reproduced the error in a small demo module that only creates a table, and then updates it. If you install the module, uncomment the commented hook_update_N() function and run update.php, the error should appear.
I am using Drupal 7.14 and MSSQL Server 2008 R2. Let me know if there is more information you need.
| Comment | File | Size | Author |
|---|---|---|---|
| sqlbugdemo.zip | 1.09 KB | dyule |
Comments
Comment #1
Uncle_Code_Monkey commentedThe SqlSrv Drupal driver does not create the __pk field correctly and a patch is currently required to correct the issue. Unfortunately, the patch must be in place before "update.php" is run, so rolling back your database is the best solution (you did perform a backup before running update.php, right?). If you do not have the option of restoring from a backup, you can read through the comments of how to manually correct your database after applying the patch.
Comment #2
david_garcia commentedOld versions for the driver where creating technical primary keys as nullable. This is fixed in current version, but for users using old version of driver they need to manually make the column non-nullable.
Follow-up here: https://www.drupal.org/node/2136849