django-shortuuidfield icon indicating copy to clipboard operation
django-shortuuidfield copied to clipboard

How fix problemm django.db.utils.IntegrityError: UNIQUE constraint failed?

Open alimuradov opened this issue 9 years ago • 9 comments

My migration has the form `# -- coding: utf-8 --

Generated by Django 1.9.2 on 2016-03-03 15:52

from future import unicode_literals

from django.db import migrations import shortuuidfield.fields

class Migration(migrations.Migration):

dependencies = [
    ('patient', '0006_auto_20160226_0005'),
]

operations = [
    migrations.AddField(
        model_name='customer',
        name='uuid',
        field=shortuuidfield.fields.ShortUUIDField(blank=True, editable=False, max_length=22, unique=True),
    ),
]

`

When I try to run migrate myapp, I get the error table patient_customer has no column named uuid

alimuradov avatar Mar 03 '16 21:03 alimuradov

@alimuradov I had this same problem, and found documentation on Adding a unique field in the migrations documentation.

Basically: You add the field without unique=true in one operation, make a data migration that generates the correct shortuuids for you, and then change the field too unique again.

EmilStenstrom avatar Apr 13 '20 20:04 EmilStenstrom

DO THESE python manage.py migrate --fake python manage.py makemigrations python manage.py migrate python manage.py runserver the above commands should sort them all out

aayobam avatar Mar 12 '21 07:03 aayobam

I'm no longer using or in a position to test this library, but am happy to review and merge any PR's that address this or other issues if you're finding the library to be helpful.

benrobster avatar Mar 12 '21 17:03 benrobster

DO THESE python manage.py migrate --fake python manage.py makemigrations python manage.py migrate python manage.py runserver the above commands should sort them all out

I didn't understand completely what happened but it's work for me Thank You <3

Mohammad-Ab avatar Sep 06 '22 19:09 Mohammad-Ab

DO THESE python manage.py migrate --fake python manage.py makemigrations python manage.py migrate python manage.py runserver the above commands should sort them all out

Thanks you, the solution is great.

OmniaOsman avatar Jan 20 '23 12:01 OmniaOsman

I get this error even after I get rid of the unique field or set it to false, which I think is a key point that no one has pointed out yet that makes the error so devious.

ghost avatar Feb 25 '23 07:02 ghost

DO THESE python manage.py migrate --fake python manage.py makemigrations python manage.py migrate python manage.py runserver the above commands should sort them all out

This doesn't work for me. There is no update between the fake and real migrations, and the database column missing error I have due to the original issue is not handled.

ghost avatar Feb 25 '23 07:02 ghost

what actually is this but its working fine

encoder43 avatar Apr 09 '23 09:04 encoder43

Tenta definir default=uuid.uuid4 do champo no model UUIDField.

italoramonlc avatar Nov 21 '23 16:11 italoramonlc