Issue
I am running a Django container on docker which depends on Postgres. Now the issue is, when I try to load the postgresql
docker-compose up
cat /tmp/dump.sql | sudo docker exec -i <container_id> psql -U <user> -d <database_name>
This imports the first few tables and gives me a lot of errors on the terminal
An example
constraint "table_id" for relation "table_name" already exists
Another example
null value in column "column_name" violates not-null constraint
Another one
insert or update on table "table_1" violates foreign key constraint "table_id"
I wanted to know is this even the right way to import this data. Plus I cant seem to drop the database as it is already being used by django.
Note: I tried with volumes where I imported the db with postgresql. But everytime I run django, the database gets reset. I am guessing it has something to do with the migrations, but I can't touch that part.
Solution
The issue was being caused because the sql dump was trying to overwrite existing db. A quick solution if you are on dev would be to
docker volume rm <volume_name>
.
And then run the cat ...
command
Answered By - Moiz Sohail Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.