I have an application in Django 2.0 and as a database engine I use MySQL. I have a problem because the database was previously created and already has records, my idea is to use this same database for the application I'm creating.
Use the command
python manage.py inspectdb > models.py
To create the models.py file which is cleaned as indicated by the models.py file that was generated.
# Este es un módulo de modelo de Django generado automáticamente.
# Tendrás que hacer lo siguiente manualmente para limpiar esto:
# * Reordenar el orden de los modelos
# * Asegúrese de que cada modelo tenga un campo con primary_key = True
# * Asegúrese de que cada ForeignKey tenga 'on_delete' establecido en el comportamiento deseado.
# * Elimine las líneas 'managed = False' si desea permitir que Django cree, modifique y elimine la tabla
# Siéntase libre de cambiar el nombre de los modelos, pero no cambie el nombre de los valores de db_table o los nombres de campo.
After this I proceed to execute:
python manage.py migrate
python manage.py makemigrations
python manage.py migrate
But it generates the following error:
(1050, "Table 'XXXXXXX' already exists")
Obviously it tells me that the table already exists, but how do I not generate this error and continue administering the tables from Django.