Translate-plugin: Integrity constraint violation: 1062 Duplicate entry '0' for key when saving record

Created on 6 Jul 2018  路  9Comments  路  Source: rainlab/translate-plugin

I have applied the following code in a number of models in a plugin .

public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
public $translatable = ['name'];

Some models have more than just the 'name' field.

When I try to update any existing records with a backend form, for some models I am getting this error:

"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' (SQL: insert into rainlab_translate_attributes (locale, model_id, model_type, attribute_data) values (ch, 32, Roojai\Services\Models\Customer, {"name":""}))" on line 664 of /home/eim42744/etak/vendor/laravel/framework/src/Illuminate/Database/Connection.php

Any ideas of what is going wrong here. I get this error even if I do not change the data in the record.

I am wondering if it is something to do with the fact that I have a field 'name' in multiple models.

Thanks for any ideas

Most helpful comment

Sorry @LukeTowers, noted!
I realised the issue was nothing to do with the plugin.
For reference, my entire database had lost AUTO_INCREMENT on its primary keys after an export/import. It was the lack of AUTO_INCREMENT for the id column in one of the tables in the plugin that was causing this problem

All 9 comments

@roojai please don't close issues without any explanation, other people may encounter the same situation that you did and would benefit from whatever the solution was.

Sorry @LukeTowers, noted!
I realised the issue was nothing to do with the plugin.
For reference, my entire database had lost AUTO_INCREMENT on its primary keys after an export/import. It was the lack of AUTO_INCREMENT for the id column in one of the tables in the plugin that was causing this problem

Awesome, thanks for the update!

How can an error similar to that be solved??

@Wambua47 please don't hijack other people's issues. Your problem is something that is highly dependent on your specific setup and will require someone knowledgeable about many facets of web development to help you out. If you would like to pay me for some dedicated time to walk you through fixing it then you can reach me on the slack: https://octobercms-slack.herokuapp.com/. Otherwise your options are to find a local developer to help you or ask for help in the general slack and see if someone is willing to walk you through it for free.

@roojai I had the same issue today. It also had to do with importing and exporting. Do you have any clue which plugin caused this?

@cheb60 Maybe look into your database tables and see if any id fields are missing the AUTO_INCREMENT attribute.

Hi @cheb60
I assumed it was something to do with my MySQL export and import files and not related to any plugin.

Its happened twice (out of many many exports) and I have no idea why. The solution was to manually set all the primary keys to autoincrement.

Hi @roojai

Alright that's also what I did to fix this for the time being. Thanks anyways!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RodrigoGalter picture RodrigoGalter  路  4Comments

Ladylain picture Ladylain  路  3Comments

anonimo9 picture anonimo9  路  5Comments

o0alexela0o picture o0alexela0o  路  4Comments

patrick-durrer picture patrick-durrer  路  7Comments