Integrity constraint violation: 1048 > Column 'entity_id' cannot be null Whenever I try and create a new node (of type article, page, blog, etc), for some reason I get thrown the following error upon hitting the save button.


  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048
  Column 'entity_id' cannot be null: INSERT INTO {pathauto_state}
  (entity_type, entity_id, pathauto) VALUES (:db_insert_placeholder_0,
  :db_insert_placeholder_1, :db_insert_placeholder_2); Array (
  [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] =>
  [:db_insert_placeholder_2] => 1 ) in pathauto_entity_state_save()
  (line 492 of /sites/all/modules/pathauto/pathauto.module).


I've tried going into the database and setting these columns to allow NULL, but this doesn't seem to fix the issue. I've also tried uninstalling and reinstalling the pathauto module, but no luck.

This error was occurring previously with a couple of other modules, and I seem to have fixed them. I'm just not sure why this error is occurring at all (e.g. I can edit and save existing nodes, but creating new ones all of a sudden is a problem?)

UPDATE: Another issue I seem to get:


  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048
  Column 'id' cannot be null: INSERT INTO {file_usage} (fid, module,
  type, id, count) VALUES (:db_insert_placeholder_0,
  :db_insert_placeholder_1, :db_insert_placeholder_2,
  :db_insert_placeholder_3, :db_insert_placeholder_4); Array (
  [:db_insert_placeholder_0] => 126 [:db_insert_placeholder_1] => file
  [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] =>
  [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 698 of
  /includes/file.inc).
Short answer

It sounds like you have some code which deletes the node ID on saved nodes causing trouble.

Longer answer.

When you create a new node, Drupal will internally make an insert to the node table to generate an ID and then use that id to populate node_field_data and node_field_revision tables (assuming you are using revisions). The ID is also set on the node entity itself and is accessed via the id() method on the Node class.

The NodeForm does a check on the node object upon being saved, and rebuild the form in case the node doesn't get an ID.

Since you don't get an error for node_field_data and node_field_revision tables, it's pretty safe to assuming that the ID generation works and the node is populated with the ID (Core has lots of test cases covering this).

Since stuff reacting to the node being saved fails, with the missing ID, some code must delete the ID after it's set. Class instances are passed by reference, meaning that if you change one instance you change it every where that class instance is used. So most likely you have some code messing stuff up. There is a good chance that it's some code implementing hook_entity_insert or hook_entity_update (or the node specific variations of those hooks).