PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to load sql dump in a containerized django docker which depends on postgres

 October 18, 2022     django, docker, postgresql     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing