I have some problem while trying to use a MySQL database with Django. The database contains a table named items
. This database is imported from a development system to a production system. This database is the second database in addition to an existing SQLite databased used by other teams. There had been an error message about no such table
, but I was able to solve it with this question. I then assume that there are no migration errors.
The MySQL database works fine in the development system (tested using python manage.py shell
), but it doesn't work in the production system (tested the same way.)
I tested the import with:
$ python manage.py shell
>> from project.models import Item
>> Item.objects.all()
<QuerySet []>
I created the models.py
file with:
$ python manage.py inspectdb > models.py
I verified that the database and the table items
actually contains records. (Although some fields are stored as unicode text, if that makes any difference to the situation.)
Here is part of the project/settings.py
file:
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'new_project': {
'NAME': 'new_project',
'ENGINE': 'django.db.backends.mysql',
'USER': 'xxxxxxxx',
'PASSWORD': 'xxxxxxxx',
}
}
...
Here is part of the generated app/models.py
:
...
class Item(models.Model):
itemid = models.AutoField(db_column='ItemID', primary_key=True) # Field name made lowercase.
name = models.TextField(blank=True, null=True)
category = models.TextField(blank=True, null=True)
kind = models.TextField(blank=True, null=True)
class Meta:
managed = True
db_table = 'items'
...
I am using Django 2.0.2
with Python 3.6.3
.