Cannot insert the value NULL into column 'uid'

Created on 26 April 2022, over 2 years ago
Updated 8 December 2023, 12 months ago

Problem/Motivation

When creating or inserting a user I get the following error

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot insert the value NULL into column 'uid', table 'dbo.users'; column does not allow nulls. 

INSERT fails.: INSERT INTO [users] ([uuid], [langcode]) OUTPUT (1) VALUES (:db_insert0, :db_insert1); Array ( [0] => Array ( [0] => 213d549a-52fa-40cf-a003-85b069578724 [1] => es ) ) en Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (linea 811 de E:\copia-drupal\web\core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php).
🐛 Bug report
Status

Active

Version

4.3

Component

User interface

Created by

🇨🇴Colombia IngJheyner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇬Egypt ydaood

    I have the same issue

  • Status changed to Postponed: needs info over 1 year ago
  • Please add steps or code to reproduce the error. I don't get this error or have any issues adding users.

  • 🇮🇳India nishantkumar155

    We are facing this as uid is not processing in updb. we moved from Drupal 8.9.20 to Drupal 9.5.7 . Due to this we are unable to create new user getting error null can not be inserted on uid.

  • Status changed to Active over 1 year ago
  • If you create a clean Drupal site with this module installed, do you have the error when inserting a user? If not, then the error could be something with your configuration or another module.

    Try starting from a new Drupal site and try to figure out the root cause. If you don't do any debugging, this issue will never get fixed, because I highly doubt anybody knows how to reproduce the issue given the information provided above.

  • 🇮🇳India raajkumar.kuru Chennai

    Issue is because of Drupal Core upgrade and Drupal already sending Notice while we doing updb
    Here is the update hook
    user_update_9301

    To resolve Follow this steps

    Open the database in SQL Management Studio.
    Right-click on the users table
    Select Script Table as -> Create to -> New Query Editor Window. This will generate a script to recreate the table in a new query window.
    Change the table name and relative keys & constraints in the script to users_temp.
    Execute the script.
    Then for copying the data run this below script:

    SET IDENTITY_INSERT users_temp ON

    INSERT Into users_temp ([Column1], [Column2], [Column3], [Column4],... )
    SELECT [Column1], [Column2], [Column3], [Column4],... FROM users

    SET IDENTITY_INSERT users_temp OFF

    Then Rename the users table to any name
    Next change the users_temp name to users and it will work.

  • 🇮🇳India nishantkumar155

    @raajKumar ,

    I confirm #14 Solved over issue , This issue should be implement over the hook level.

  • 🇬🇧United Kingdom pstewart

    Noting that the underlying issue that caused this problem in 🐛 Upgrading to Drupal 9.3.x changes users table and locks users out of the site Needs work has now been fixed in 4.4.x, however an update hook would still need to be implemented to facilitate upgrades to 9.3.x. By this point that's probably not going to happen as most affected people will already have done a manual workaround with 4.3, and D9 is now EOL. I'll leave this issue open for now for discoverability and in case anyone wants to have a go at implementing the required hook, otherwise this should be considered as 'Closed (won't fix)'. Anyone still running into this problem can either apply the workaround in #14 or attempt to run the pertinent lines from the original user_update_9301 implementation:

    $connection = \Drupal::database();
    $connection->schema()->dropPrimaryKey('users');
    $connection->schema()->changeField('users', 'uid', 'uid', ['type' => 'serial', 'not null' => TRUE], ['primary key' => ['uid']]);
    
Production build 0.71.5 2024