Home > Database > Mysql Tutorial > body text

How to Recreate Deleted Database Tables in Django?

Linda Hamilton
Release: 2024-11-08 03:38:02
Original
248 people have browsed it

How to Recreate Deleted Database Tables in Django?

Recreating Database Table After Deletion in Django

In Django, dropping tables related to an app can lead to errors while trying to synchronize the database with the current models. The error message "Table 'someapp.feed' doesn't exist" indicates that the expected table is missing.

To address this issue and recreate the necessary tables for the app, follow these steps:

  1. Drop Existing Tables: (Already performed)
  2. Comment Out Model Definition: In the models.py file, comment out the definition of the model that was related to the dropped table.
  3. Execute Migrations:

    • If Django version >= 1.7:

      • python manage.py makemigrations
      • python manage.py migrate --fake
    • If Django version < 1.7:

      • python manage.py schemamigration someapp --auto
      • python manage.py migrate someapp --fake
  4. Uncomment Model Definition: Remove the comments from the model definition in models.py.
  5. Execute Migrations (without --fake): Repeat step 3, but this time without the --fake flag. This will actually apply the migrations and create the desired table.

The above is the detailed content of How to Recreate Deleted Database Tables in Django?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!