0

I'm trying to import a .csv file into my Django db.sqlite3 and I followed exactly as the the instructions from a Youtube video. However, there are a couple of rows in my .csv file that have the same latitude and longtitude values and sqlite3 fails to import some rows as the latitute and longtitude already appear in the table.

sqlite> .import venues.csv myapi_venue
venues.csv:17: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:44: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:49: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:60: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:66: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:73: INSERT failed: UNIQUE constraint failed: myapi_venue.name
venues.csv:80: INSERT failed: UNIQUE constraint failed: myapi_venue.name

I tried to force the model to have unique as False, but it doesn't help.

class venue(models.Model):
    
    name = models.CharField(_("name"), primary_key=True, max_length=300)
    address = models.CharField(_("address"), max_length=300, unique=False)
    categories = models.CharField(_("category"), null=True, max_length=300, unique=False)
    latitude = models.FloatField(_("latitude"), max_length=150, unique=False)
    longitude = models.FloatField(_("longitude"), max_length=150, unique=False)

When I try migrate the changes, it shows this:

$ python manage.py makemigrations
  No changes detected

How do I import all the rows into the database?

So i can prove that the primary keys are unique: conflicting rows

I think I found the reason why it shows errors. The primary key in the model is matched with a different column in the csv for some reason. order of columns is messed up

Shoreo
  • 1
  • 1

1 Answers1

-1

So I eventualy had to delete the original table and create a new one so the columns are in the correct order. Followed solutions from how to recreate a deleted table with django migrations

Shoreo
  • 1
  • 1