[django]Error: contenttypes couldn't be reset

1.4k Views Asked by At

I reset contenttypes prior to loading the fixture (Refer to Problems with contenttypes when loading a fixture in Django).

But contenttypes couldn't be reset:

...project_dir > manage.py reset contenttypes

You have requested a database reset. This will IRREVERSIBLY DESTROY any data for the "contenttypes" application in the database "my_database". Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

Error: Error: contenttypes couldn't be reset. Possible reasons:

  • The database isn't running or isn't configured correctly.
  • At least one of the database tables doesn't exist.
  • The SQL was invalid.

Hint: Look at the output of 'django-admin.py sqlreset contenttypes'. That's the SQL this command wasn't able to run.

The full error: (1217, 'Cannot delete or update a parent row: a foreign key cons traint fails')

Any help will be greatly appreciated. Thank you!

1

There are 1 best solutions below

0
On

On the question you posted there is another answer - use natural keys for fixtures.

The error "Cannot delete or update a parent row: a foreign key cons traint fails" means that the content type row can't be deleted as there is another object that points to that row. E.g. if there is any none-blank generic foreign key relation that would be the case.

If you really need to reset the content-type app you can get the SQL command that is needed for this and alter it to use CASCADE statement. However this is dangerous as it will delete not only content types but also rows from another tables that points to content-types.

So I advice to re-create fixtures using natural keys.