0

Stack

PostgresQL 9.3 on Ubuntu 18.04
Django 3.0 with DRF

Problem

I am trying to build a model with the below desired models.py. But I used the pythonic way to name variables, but I now realize that PostgreSQL ignores the "_", thus "region" and "region_number" appear to be the same key.

region_number should be regionNumber

My question is how to I correct this?

What I have tried:

  1. Simply correcting the model element names and migrating - error is still there
  2. Migrating back to before I applied this migration
  3. Dropping the Index in SQL; returns "cannot drop index XXX_Index because constraint XXX_Index on table (my_table_name) requires it

CURRENT models.py

from django.db import models


class DataInput(models.Model):

    name = models.CharField(max_length=45)
    country = models.CharField(max_length=55)
    region = models.CharField(max_length=55)
    region_number = models.IntegerField()

Error python manage.py migrate

psycopg2.errors.UniqueViolation: could not create unique index "Region and Number"
DETAIL:  Key (region, region_number)=(US EAST, 1) is duplicated.

DESIRED models.py

from django.db import models

class DataInput(models.Model):

    name = models.CharField(max_length=45)
    country = models.CharField(max_length=55)
    region = models.CharField(max_length=55)
    regionNumber = models.IntegerField()

Thanks so much!

yen936
  • 53
  • 7
  • https://stackoverflow.com/questions/38084864/how-to-escape-underscores-in-postgresql See if this solves your problem. – Arosh Jul 16 '20 at 04:27
  • SOLVED: There was a test DataInput row that I forgot about. So the error had nothing to do with the name of the column, just the fact that values --that were supposed to be unique--were duplicated. – yen936 Jul 17 '20 at 00:15

0 Answers0