-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: constraint does not exist when restoring a backup on a fresh db #245
Comments
I solved my issue by removing all the DROP lines, and replacing
but being able to load dumps in this case would be super cool :D |
Hello @MickaelBergem We encountered this problem several time with PostgreSQL and the There's a PR about that here: #241 |
Thanks for the quick reply @ZuluPro I'll try to test it next week :) |
I also encounter this problem when I create a backup from my staging database and try to restore it into my local development database. Is there a recommended work-around for this problem? Thanks! |
@ZuluPro I just tried it with your branch:
It looks like this does not solve my problem :/ |
@MickaelBergem thanks for you tests |
@ZuluPro I'm kind of confused here, how do I use the new connector? Doesn't the pip install take everything needed from your branch? For now, the manual steps I take to restore a dump from another host:
That's all folks. |
@MickaelBergem, Something like:
|
I tried to use the new connector both with However, I got an error Full error message: root@a468a0f5530f:/code# ./manage.py dbbackup
/usr/local/lib/python2.7/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead
RemovedInDjango110Warning)
ImportError: No module named postgres
File "/usr/local/lib/python2.7/site-packages/dbbackup/utils.py", line 111, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/dbbackup/management/commands/dbbackup.py", line 58, in handle
self.connector = get_connector(database_key)
File "/usr/local/lib/python2.7/site-packages/dbbackup/db/base.py", line 41, in get_connector
module = import_module(connector_module_path)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
Traceback (most recent call last):
File "./manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/dbbackup/utils.py", line 111, in wrapper
func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/dbbackup/management/commands/dbbackup.py", line 58, in handle
self.connector = get_connector(database_key)
File "/usr/local/lib/python2.7/site-packages/dbbackup/db/base.py", line 41, in get_connector
module = import_module(connector_module_path)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named postgres Any ideas @ZuluPro ? |
@mikeschaekermann Did you set any conf ? |
I set the following in
In which directory should I delete *.pyc files? I tried to delete them in the directory with |
So is it already possible to restore a backup on a fresh database and how would I do it? |
The problem with
@thimma11 you should just install dbbackup==3.2.0 and then set the connector settings as above, then dbbackup/dbrestore should work. |
All settings specified above doesn't work for my installation, so I suppose the built-in dbrestore doesn't work at all for postgres. But I was able to restore database by psql directly, actually it's not so hard.
Media restore works ok, so I'm satisfied :) |
@zxwild Yeah I've found that to make the initial restoration, I can't use the dbrestore command, but using the psql command works fine |
Hello all, |
@ZuluPro it was an initial database with about 30 records |
Yep same here.. Think it was something like 1.6Mb on a fresh site where I wanted to replicate some data from prod to dev. |
Major +1 |
+1 |
2 similar comments
+1 |
+1 |
still relevant after 3 years... |
Still relevant but @zxwild's workaround works just fine 😄 |
+1 |
Still relevant for Unfortunetly |
As stated before the media restore works flawlessly but in case you are using dockerized Postgres and wanna migrate/copy/clone database following commands can help. This will create a SQL file with data only
Before restoring you must run the migrations on the new host so that the new database has the tables in place before restoring.
|
I reckon I may have just hit this with Django 3.2 and python 3.10 and |
have the same thing, have to run it twice |
+1 |
Solved this by adding to settings.py: DBBACKUP_CONNECTORS = {
'default': {
'RESTORE_SUFFIX': '--if-exists',
},
} |
@sergeydubak Are you interested in either documenting this, or PRing this behavior as the default for the |
@sergeydubak you saved my ass after 1 week of trying to figure out how to solve this (to run migrations, to use the postgres command, etc). This is great tip, and completely easy to add to the settings. I hope you can open a PR for at least the documentation upgrade, although I have a feeling this could have just been the default option. |
=> Works fine ✅
=> I get the following error ❌
I guess the issue comes from constraint name not being constant (
2579dee5
par above).Why not use
IF NOT EXIST
(https://www.postgresql.org/docs/9.0/static/sql-altertable.html) ?Or simply wipe out the whole database before importing and remove all the DROP commands?
I guess I miss some historical data (reasons behind decisions), but for now I have a hard time figuring how to restore this dump without manual edit of the relevant lines.
The text was updated successfully, but these errors were encountered: