I am getting an error trying to save a new content or update it that contains paragraphs.

I am using Drupal core 8.4.0, Paragraphs 8.x-1.2 and psql (PostgreSQL) 9.6.5 in Ubuntu 17.04, all the last versions including last versions of all the modules used in Drupal.

I have tried also with the dev version of paragraphs without result.

The error that I am getting is:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "paragraphs_item_revision____pkey" DETAIL: Key (revision_id)=(37) already exists.: INSERT INTO paragraphs_item_revision (id, langcode, revision_uid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Zeile 805 in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Any idea how to solve this problem? Or what I could try?

Comments

dimr created an issue. See original summary.

dimr’s picture

Title: Error Saving nodw » Error SQLSTATE[23505]: Unique violation Saving Node
johnchque’s picture

Hmmm this is pretty strange, do you have a similar problem when using other referenced entities? Not really sure what could be the cause this to affect to Paragraphs only.

dimr’s picture

I have tried in another content type with an entity reference field to a content, and it works...
In the meanwhile, I have updated to 8.4.2 but I still have the same error.

Any idea that I could try?

johnchque’s picture

It seems pretty strange, it is like the id has not been incremented when added a new Paragraph. Did you have some error when trying to save a node with Paragraphs that showed you a WSOD or something like that?

dimr’s picture

Hi,

I don't remember to see something like that. I have tried also with dev version but it is not working either.

Looking for some information I have found this that maybe can be the problem, but I am afraid that even with that information, I have tried to debug the error, but I don't see anywhere in the code where I could check that.

https://dba.stackexchange.com/a/130121


Postgres handles auto incrementing a little differently than MySQL does. In Postgres, when you create the serial field, you are also creating a sequence field that is keeping track of the id to use. This sequence field is going to start out with a value of 1.

When you insert a new record into the table, if you don't specify the id field, it will use the value of the sequence, and then increment the sequence. However, if you do specify the id field, then the sequence is not used, and it is not updated, either.

dimr’s picture

I have tried with a new Drupal instance 8.4.2 and the same paragraph module version, and I cannot reproduce the error.
I have created a new content type with a new paragraph type in the problematic project and the problem still appear.

Anyone has any idea that I could try, please?

dimr’s picture

Issue tags: +Entity Reference
dimr’s picture

Status: Active » Closed (won't fix)

Finally, yongt9412 where right and it was a problem directly from the database, the last_value was outdated, and we resolved it updating "manually the value"

Before was:

database_name=# \d paragraphs_item_revision_revision_id_seq
     Sequence "public.paragraphs_item_revision_revision_id_seq"
    Column     |  Type   |                  Value
---------------+---------+------------------------------------------
sequence_name | name    | paragraphs_item_revision_revision_id_seq
last_value    | bigint  | 42
start_value   | bigint  | 1
increment_by  | bigint  | 1
max_value     | bigint  | 9223372036854775807
min_value     | bigint  | 1
cache_value   | bigint  | 1
log_cnt       | bigint  | 32
is_cycled     | boolean | f
is_called     | boolean | t
Owned by: public.paragraphs_item_revision.revision_id

but the real last value was 141, then we change it to

database_name=# \d paragraphs_item_revision_revision_id_seq
     Sequence "public.paragraphs_item_revision_revision_id_seq"
    Column     |  Type   |                  Value
---------------+---------+------------------------------------------
sequence_name | name    | paragraphs_item_revision_revision_id_seq
last_value    | bigint  | 141
start_value   | bigint  | 1
increment_by  | bigint  | 1
max_value     | bigint  | 9223372036854775807
min_value     | bigint  | 1
cache_value   | bigint  | 1
log_cnt       | bigint  | 0
is_cycled     | boolean | f
is_called     | boolean | f
Owned by: public.paragraphs_item_revision.revision_id

Thanks for the support!