django-dbbackup
django-dbbackup copied to clipboard
Error in db restore: no such table
When I try to restore the database I receive
dbbackup/db/sqlite.py:74: UserWarning: Error in db restore: no such table: main.auth_group_permissions
warnings.warn("Error in db restore: {}".format(err))
Hello @rgaiacs Could you check your backup file to look if the table is created before (or after) ?
Be backup starts with
CREATE TABLE "auth_group" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "nam
e" varchar(80) NOT NULL UNIQUE);
CREATE UNIQUE INDEX "auth_group_permissions_group_id_permission_id_0cd325b0_uniq
" ON "auth_group_permissions" ("group_id", "permission_id");
CREATE INDEX IF NOT EXISTS "auth_group_permissions_group_id_b120cbf9" ON "auth_g
roup_permissions" ("group_id");
CREATE INDEX IF NOT EXISTS "auth_group_permissions_permission_id_84c5c92e" ON "a
uth_group_permissions" ("permission_id");
and later it has
CREATE TABLE "auth_group_permissions" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "group_id" integer NOT NULL REFERENCES "auth_group" ("id"), "permission_id" integer NOT NULL REFERENCES "auth_permission" ("id"));
CREATE UNIQUE INDEX "auth_group_permissions_group_id_permission_id_0cd325b0_uniq" ON "auth_group_permissions" ("group_id", "permission_id");
CREATE INDEX IF NOT EXISTS "auth_group_permissions_group_id_b120cbf9" ON "auth_group_permissions" ("group_id");
CREATE INDEX IF NOT EXISTS "auth_group_permissions_permission_id_84c5c92e" ON "auth_group_permissions" ("permission_id");
@rgaiacs Hmmm, Does the table is created after the INSERTs ?
the --clean option for postgresql needs to add --if-exists
this is what causes this error https://github.com/django-dbbackup/django-dbbackup/blob/master/dbbackup/db/postgresql.py#L51
but it honestly is a good thing and you should simply add --if-exists when adding --clean
link to pg_dump docs: https://www.postgresql.org/docs/10/app-pgdump.html
I've been receiving the same warnings:
'UserWarning: Error in db restore: no such table: main.auth_permission warnings.warn("Error in db restore: {}".format(err))'
and some anothers:
'UserWarning: Error in db restore: FOREIGN KEY constraint failed warnings.warn("Error in db restore: {}".format(err))'
'UserWarning: Error in db restore: index django_content_type_app_label_model_76bd3d3b_uniq already exists warnings.warn("Error in db restore: {}".format(err))'
Any suggestions? ( I'm using SQLite3)
I've been receiving the same warnings:
'UserWarning: Error in db restore: no such table: main.auth_permission warnings.warn("Error in db restore: {}".format(err))'
and some anothers:
'UserWarning: Error in db restore: FOREIGN KEY constraint failed warnings.warn("Error in db restore: {}".format(err))'
'UserWarning: Error in db restore: index django_content_type_app_label_model_76bd3d3b_uniq already exists warnings.warn("Error in db restore: {}".format(err))'
Any suggestions? ( I'm using SQLite3)
Is your problem resolved since then? I have almost the same problem with SQLite3 as well and could not find any useful issue pointing out this particular problem.
If I run the dbrestore
command twice, all of my records are restored with a bunch of more "UserWarning: Error in ...". But, I should have run it once, right? Or twice 🤔?
Having the same issue, where the tables are created in alphabetical order and this creates conflicts:
class ExpenseType(models.Model):
name = models.CharField(max_length=15, unique=True)
position = models.IntegerField(
unique=True,
help_text="Column position in grouped reports.",
)
class Expense(models.Model):
related_date = models.DateField(help_text="Date that the expense is accounted to.")
value = models.DecimalField(max_digits=6, decimal_places=2)
target = models.ForeignKey(to=ExpenseType, on_delete=models.PROTECT)
paid_by = models.ForeignKey(
to=UserModel,
on_delete=models.PROTECT,
null=True,
blank=True,
)
comment = models.TextField(
max_length=200,
null=True,
blank=True,
)
The the models above, result in this in the dump:
CREATE TABLE IF NOT EXISTS "expenses_expense" (... "expenses_expensetype" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "expenses_expensetype"...;
Which then results in UserWarning: Error in db restore: no such table: main.expenses_expensetype