Skip to content
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 in db restore: no such table #257

Open
rgaiacs opened this issue Aug 18, 2017 · 7 comments
Open

Error in db restore: no such table #257

rgaiacs opened this issue Aug 18, 2017 · 7 comments
Assignees
Labels
bug Bugs that need to get fixed. db/sqlite

Comments

@rgaiacs
Copy link
Contributor

rgaiacs commented Aug 18, 2017

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))
@ZuluPro
Copy link
Contributor

ZuluPro commented Aug 20, 2017

Hello @rgaiacs
Could you check your backup file to look if the table is created before (or after) ?

@ZuluPro ZuluPro self-assigned this Aug 20, 2017
@ZuluPro ZuluPro added bug Bugs that need to get fixed. database db/sqlite labels Aug 20, 2017
@rgaiacs
Copy link
Contributor Author

rgaiacs commented Aug 20, 2017

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");

@ZuluPro
Copy link
Contributor

ZuluPro commented Aug 20, 2017

@rgaiacs Hmmm,
Does the table is created after the INSERTs ?

@budlight
Copy link

budlight commented May 7, 2020

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

@ramonamg17
Copy link

ramonamg17 commented Sep 9, 2020

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)

@tustunkok
Copy link

tustunkok commented Sep 14, 2021

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 🤔?

@emiliyan-rashev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs that need to get fixed. db/sqlite
Projects
None yet
Development

No branches or pull requests

8 participants