У меня есть приложение Django со стандартной БД sqlite3. Теперь я хочу использовать MySQL. Таким образом, я изменил свой DATABASES
в settings.py
, и он работает хорошо, но я не могу запустить сервер, потому что он говорит
django.db.utils.InternalError: (1049, "Unknown database 'django'")
Итак, я создал эту БД в клиенте, и теперь он говорит
django.db.utils.ProgrammingError: (1146, "Table 'django.Cat' doesn't exist")
Похоже, мне приходится создавать все таблицы самостоятельно, что является худшим вариантом, который я могу сделать.
#settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/db.conf',
},
}
}
и
#conf.db
[client]
database = django
host = localhost
user = DjangoUser
password = password_you_cant_guess
default-character-set = utf8
Как заставить Django создать все таблицы, которые у меня есть?
Я даже не могу запустить python3 manage.py
с какой-либо командой, потому что это дает мне это исключение.
Traceback:
Traceback (most recent call last):
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'django.Cat' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/path/to/project/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/path/to/project/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/path/to/project/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path/to/project/venv/lib/python3.6/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/path/to/project/External/apps.py", line 13, in ready
active_cats = list(Cat.objects.filter(active_cat=True).all())
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/models/query.py", line 276, in __iter__
self._fetch_all()
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1151, in execute_sql
cursor.execute(sql, params)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/path/to/project/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/path/to/project/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'django.Cat' doesn't exist")