PDOException: SQLSTATE[HY000]: General error: 1364 Field 'wid' doesn't have a default value

Created on 22 July 2015, about 9 years ago
Updated 7 August 2024, about 2 months ago

DROP TABLE IF EXISTS `watchdog`;
CREATE TABLE `watchdog` (
`wid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key: Unique watchdog event ID.',
`uid` int(11) NOT NULL DEFAULT '0' COMMENT 'The users.uid of the user who triggered the event.',
`type` varchar(64) NOT NULL DEFAULT '' COMMENT 'Type of log message, for example "user" or "page not found."',
`message` longtext NOT NULL COMMENT 'Text of log message to be passed into the t() function.',
`variables` longblob NOT NULL COMMENT 'Serialized array of variables that match the message string and that is passed into the t() function.',
`severity` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
`link` varchar(255) DEFAULT '' COMMENT 'Link to view the result of the event.',
`location` text NOT NULL COMMENT 'URL of the origin of the event.',
`referer` text COMMENT 'URL of referring page.',
`hostname` varchar(128) NOT NULL DEFAULT '' COMMENT 'Hostname of the user who triggered the event.',
`timestamp` int(11) NOT NULL DEFAULT '0' COMMENT 'Unix timestamp of when event occurred.',
PRIMARY KEY (`wid`),
KEY `type` (`type`),
KEY `uid` (`uid`),
KEY `severity` (`severity`)
) ENGINE=InnoDB AUTO_INCREMENT=811 DEFAULT CHARSET=utf8 COMMENT='Table that contains logs of all system events.';

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[HY000]: General error: 1364 Field 'item_id' doesn't have a default value: INSERT INTO "queue" ("name", "data", "created") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => update_fetch_tasks [:db_insert_placeholder_1] => a:6:{s:4:"name";s:6:"drupal";s:4:"info";a:6:{s:4:"name";s:14:"Automated Cron";s:7:"package";s:4:"Core";s:7:"version";s:6:"10.0.9";s:7:"project";s:6:"drupal";s:9:"datestamp";i:1683108678;s:16:"_info_file_ctime";i:1685262390;}s:9:"datestamp";i:1683108678;s:8:"includes";a:46:{s:14:"automated_cron";s:14:"Automated Cron";s:8:"big_pipe";s:7:"BigPipe";s:5:"block";s:5:"Block";s:13:"block_content";s:12:"Custom Block";s:10:"breakpoint";s:10:"Breakpoint";s:9:"ckeditor5";s:10:"CKEditor 5";s:7:"comment";s:7:"Comment";s:6:"config";s:21:"Configuration Manager";s:7:"contact";s:7:"Contact";s:10:"contextual";s:16:"Contextual Links";s:8:"datetime";s:8:"Datetime";s:5:"dblog";s:16:"Database Logging";s:18:"dynamic_page_cache";s:27:"Internal Dynamic Page Cache";s:6:"editor";s:11:"Text Editor";s:5:"field";s:5:"Field";s:8:"field_ui";s:8:"Field UI";s:4:"file";s:4:"File";s:6:"filter";s:6:"Filter";s:4:"help";s:4:"Help";s:7:"history";s:7:"History";s:5:"image";s:5:"Image";s:14:"layout_builder";s:14:"Layout Builder";s:16:"layout_discovery";s:16:"Layout Discovery";s:4:"link";s:4:"Link";s:17:"menu_link_content";s:17:"Custom Menu Links";s:7:"menu_ui";s:7:"Menu UI";s:5:"mysql";s:5:"MySQL";s:4:"node";s:4:"Node";s:7:"options";s:7:"Options";s:10:"page_cache";s:19:"Internal Page Cache";s:4:"path";s:4:"Path";s:10:"path_alias";s:10:"Path alias";s:6:"search";s:6:"Search";s:8:"shortcut";s:8:"Shortcut";s:6:"system";s:6:"System";s:8:"taxonomy";s:8:"Taxonomy";s:4:"text";s:4:"Text";s:7:"toolbar";s:7:"Toolbar";s:4:"tour";s:4:"Tour";s:6:"update";s:14:"Update Manager";s:4:"user";s:4:"User";s:5:"views";s:5:"Views";s:8:"views_ui";s:8:"Views UI";s:8:"standard";s:8:"Standard";s:7:"stable9";s:8:"Stable 9";s:5:"claro";s:5:"Claro";}s:12:"project_type";s:4:"core";s:14:"project_status";b:1;} [:db_insert_placeholder_2] => 1687605552 ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 43 of core\modules\mysql\src\Driver\Database\mysql\ExceptionHandler.php).
Drupal\Core\Database\StatementWrapper->execute(Array, Array) (Line: 44)
Drupal\mysql\Driver\Database\mysql\Insert->execute() (Line: 95)
Drupal\Core\Queue\DatabaseQueue->doCreateItem(Array) (Line: 68)
Drupal\Core\Queue\DatabaseQueue->createItem(Array) (Line: 125)
Drupal\update\UpdateProcessor->createFetchTask(Array) (Line: 288)
update_get_available() (Line: 38)
update_requirements('runtime') (Line: 96)
update_page_top(Array) (Line: 352)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'update') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_top', Object) (Line: 349)
Drupal\Core\Render\MainContent\HtmlRenderer->buildPageTopAndBottom(Array) (Line: 146)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 168)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 686)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated about 11 hours ago

Created by

🇻🇳Vietnam kienan91

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • First commit to issue fork.
  • I have same issue and i replace given below in SQL query but still not get solve pages not working but
    I cannot able to edit After login content, confi

  • 🇨🇦Canada Sseto

    Hey Sharma007, I have the exact same issue too. Were you able to figure it out?

  • 🇺🇸United States bsanders44

    The most likely cause of this issue (and similar ones with other tables) is that your SQL got truncated when being imported. Typically this happens when you're importing your database via PHPMyAdmin or similar software, and the request times out. Sometimes, though, it happens when there's some kind of typo or issue in the SQL file. I've also seen it when there's nothing wrong with the SQL file itself, but for some reason an old table is not being fully dropped in the database before re-importing.

    Either way, when an error occurs during import, the remaining SQL statements are not executed. Since the errors are often towards the end of the file, most of the statements are run, resulting in a database that appears to be complete, but which is missing many of the later statements that set default values and incriminators for tables. The lack of those features on the tables is what's resulting in the errors folks are reporting here.

    You can try fixing your tables one by one, but it's very difficult. A better option is to:

    1) Clear your database completely (i.e. drop all tables) and verify there are no lingering tables.
    2) Re-import your SQL file, ideally from the command line to ensure there are no network issues.
    3) Watch for any errors during import. If there are errors, you may need to manually remove the offending SQL statements in the import file.

    If you can get the SQL to import with no issue (and assuming you've got a complete SQL dump to begin with), your issues should resolve.

  • 🇩🇰Denmark Uv516 Denmark

    On Drupal 10.2.5, PHP 8.2.17, MySQL db 8.0.36-28:

    I have a similar problem, but it's not because I imported the database.
    When searching on Google, I have seen that the error can occur when the site is a subsite of another site. That is exactly the case for me.
    I have tested two sites that are subsites and two other sites that are main sites.
    On my subsites the problem occurs, but on my main sites there is no problem. (The provider is the same: Simply.com).
    I have attached a file with error examples similar to the above.

  • 🇮🇳India amittgaur Chandigarh

    Hi

    I was able to fix this issue:

    Drupal\Core\Database\DatabaseExceptionWrapper</em>: SQLSTATE[HY000]: General error: 1364 Field &#039;item_id&#039; doesn&#039;t have a default value: INSERT INTO {queue} (name, data, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2);

    This is because of queue table item_id.
    What i did is: to browse the table queue and change item_id as unique and auto increment. you can do it via query OR form phpmyadmin table structure.

    All admin links are working to me now..

    Thank you!

  • 🇬🇧United Kingdom Alperian

    Astonishing that kienan91's 9 year old SQL fix worked for me!

  • 🇳🇿New Zealand quietone

    8 years ago steps to reproduce this problem were asked for and none have been provided. Can anyone supply that?

    This was also reported against different tables, and in Drupal 7 and Drupal 10.2. Comment #49 suggests this is caused during import of a database. Can anyone who has experienced this confirm that an import of the site database was done before the error started happening. In other words, we still need steps to reproduce.

    Since we need more information to move forward with this issue, I am leaving the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • Status changed to Needs review about 2 months ago
  • 🇺🇦Ukraine alex.mazaltov

    It is a very rare issue to happen with Drupal and it happened to me with aws migration process.

    Fixing the watchdog table and queue table is not enough cause there may be other tables broken like in my case with the domain module and so on.

    I did some research and I came up with a possible solution designed to fix the schema for all tables in the broken database.

    Please help me to test his approach.

    This approach to fix schema in broken DB using ddev with both databases .

    Here is the overview of the solution described in my gist

    SELECT 
        CONCAT(
            'ALTER TABLE `', t.TABLE_NAME, '` ',
            GROUP_CONCAT(
                CASE
                    WHEN c.COLUMN_NAME IS NULL THEN CONCAT('ADD COLUMN `', sc.COLUMN_NAME, '` ', sc.COLUMN_TYPE, ' ', 
                        IF(sc.IS_NULLABLE = 'NO', 'NOT NULL', 'NULL'), 
                        IF(sc.COLUMN_DEFAULT IS NOT NULL, CONCAT(' DEFAULT ', IF(sc.COLUMN_DEFAULT = 'CURRENT_TIMESTAMP', sc.COLUMN_DEFAULT, CONCAT('''', sc.COLUMN_DEFAULT, ''''))), ''),
                        IF(sc.EXTRA != '', CONCAT(' ', sc.EXTRA), '')
                    )
                    WHEN sc.COLUMN_TYPE != c.COLUMN_TYPE OR sc.IS_NULLABLE != c.IS_NULLABLE OR sc.COLUMN_DEFAULT != c.COLUMN_DEFAULT OR sc.EXTRA != c.EXTRA 
                    THEN CONCAT('MODIFY COLUMN `', c.COLUMN_NAME, '` ', sc.COLUMN_TYPE, ' ', 
                        IF(sc.IS_NULLABLE = 'NO', 'NOT NULL', 'NULL'), 
                        IF(sc.COLUMN_DEFAULT IS NOT NULL, CONCAT(' DEFAULT ', IF(sc.COLUMN_DEFAULT = 'CURRENT_TIMESTAMP', sc.COLUMN_DEFAULT, CONCAT('''', sc.COLUMN_DEFAULT, ''''))), ''),
                        IF(sc.EXTRA != '', CONCAT(' ', sc.EXTRA), '')
                    )
                END
                SEPARATOR ', '
            ),
            ';'
        ) AS alter_statement
    FROM 
        information_schema.TABLES t
    JOIN 
        information_schema.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA
    LEFT JOIN 
        information_schema.COLUMNS sc ON t.TABLE_NAME = sc.TABLE_NAME AND c.COLUMN_NAME = sc.COLUMN_NAME AND sc.TABLE_SCHEMA = 'source_database'
    WHERE 
        t.TABLE_SCHEMA = 'target_database'
        AND (sc.COLUMN_TYPE != c.COLUMN_TYPE OR sc.IS_NULLABLE != c.IS_NULLABLE OR sc.COLUMN_DEFAULT != c.COLUMN_DEFAULT OR sc.EXTRA != c.EXTRA)
    GROUP BY 
        t.TABLE_NAME
    HAVING 
        alter_statement IS NOT NULL;
    ddev mysql < schema_export.sql
    ddev mysql < alter_statements.sql
    
  • Status changed to Needs work about 2 months ago
  • 🇺🇸United States smustgrave

    Sounds like a potential valid bug.

    Maybe need a test case to show the issue?

Production build 0.71.5 2024