'I am not able to migrate mysql database

I connected two databases in my project PostgreSQL and MySQL. In MySQL, I have my all models in the models folder. So I want to migrate them that I can see tables in the MySQL database and put some data in it.

When I run the migrate first then there is the table name called django_migrations is created. And whenever check my databases using MySQL Command Line then this is the only table I see.

I don't know why I am not able to see my other tables. I want to know what am I doing wrong that my PMS database is not migrating.

When I run python manage.py makemigrations pms then this is showing:

Migrations for 'pms':
  pms\migrations\0001_initial.py
    - Create model Assignment
    - Create model BankAccount
    - Create model City
    - Create model Country
    - Create model House
    - Create model HouseOffering
    - Create model HouseOwnership
    - Create model Invoice
    - Create model InvoiceItem
    - Create model InvoiceParticipation
    - Create model InvoicePaymentParticipation
    - Create model Lease
    - Create model Locality
    - Create model Payment
    - Create model PaymentAdjustment
    - Create model PaymentBill
    - Create model PmsSubscription
    - Create model Society
    - Create model TenantRentPaymentBill
    - Create model User

And after that when I migrate python manage.py migrate --database=pms this is showing:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_celery_results, pms, sessions
Running migrations:
  No migrations to apply.

settings.py

DATABASES = {
    'default': {},
    'django': {
        'ENGINE': 'django.db.backends.postgresql',
        'HOST': DJANGO_DB_HOST,
        'PORT': DJANGO_DB_PORT,
        'USER': DJANGO_DB_USERNAME,
        'PASSWORD': DJANGO_DB_PASSWORD,
        'NAME': DJANGO_DB_NAME,
    },
    'pms': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': PMS_DB_HOST,
        'PORT': PMS_DB_PORT,
        'USER': PMS_DB_USERNAME,
        'PASSWORD': PMS_DB_PASSWORD,
        'NAME': PMS_DB_NAME,
    }
}

Update!

models/country.py

class Country(models.Model):
    currency = models.CharField(max_length=255, blank=True, null=True)
    name = models.CharField(max_length=255, blank=True, null=True)
    created_at = models.DateTimeField(db_column='createdAt', auto_now_add=True)  # Field name made lowercase.
    updated_at = models.DateTimeField(db_column='updatedAt', auto_now=True)  # Field name made lowercase.
    beats_database_id = models.IntegerField(db_column='beatsDatabaseId', blank=True, null=True)  # Field name made lowercase.

    class Meta:
        # managed = False
        db_table = 'countries'

When I comment managed = False then this error is showing:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_celery_results, pms, sessions
Running migrations:
  Applying pms.0003_alter_country_table...Traceback (most recent call last):
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'azuro.countries' doesn't exist")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\core\management\commands\migrate.py", line 246, in handle
    fake_initial=fake_initial,
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\migrations\migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\migrations\operations\models.py", line 469, in database_forwards
    new_model._meta.db_table,
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\base\schema.py", line 452, in alter_db_table
    "new_table": self.quote_name(new_db_table),
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute
    cursor.execute(sql, params)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\python\Azuro\azurovenv\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "C:\python\Azuro\azurovenv\lib\site-packages\MySQLdb\connections.py", line 254, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'azuro.countries' doesn't exist")

I don't know what is happening, it's my time that I'm using MySQL with Django.

Please help me!!

Thanks in Advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source