Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alimuradov opened this issue Mar 3, 2016 · 9 comments

Comments

@alimuradov
Copy link

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

@EmilStenstrom
Copy link

@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.

@aayobam
Copy link

aayobam commented Mar 12, 2021

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

@benrobster
Copy link
Owner

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.

@Mohammad-Ab
Copy link

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

@OmniaOsman
Copy link

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.

@ghost
Copy link

ghost commented Feb 25, 2023

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
Copy link

ghost commented Feb 25, 2023

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.

@encoder43
Copy link

what actually is this but its working fine

@italoramonlc
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants