django.db.utils.ProgrammingError: relation already exists

前端 未结 12 834
一向
一向 2020-12-23 14:11

I\'m trying to set up the tables for a new django project (that is, the tables do NOT already exist in the database); the django version is 1.7 and the db back end is Postgr

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 14:52

    Do not try to use --fake, because with this you risk corrupting your database.

    Instead, you can backup your current database, recreate it, and then apply backup.

    1. Create backup: pg_dump -F c -v -h localhost -f tmp/.psql

    2. Recreate it: rails db:drop db:create

    3. Restore backup: pg_restore --exit-on-error --verbose --dbname= tmp/.psql

提交回复
热议问题