Closed children1987 closed 4 years ago
初始化数据库报错的你解决了吗?这个报错就是docker pull init-db 不存在的一个仓库
能说的再清楚些吗?我该如何处理?
后来我注释掉了这些代码后,初始化DB成功了:
apps/mgmt/initialize.py:
permission, is_new = models.Permission.objects.get_or_create(name="read_all") permission.alias = "所有可读" permission.save()
permission, is_new = models.Permission.objects.get_or_create(name="write_all") permission.alias = "所有可写" permission.save()
tables = models.Table.objects.all() for table in tables: add_table(table)
`(cmdb) C:\repo_git\cmdb\gitee\cmdb>python manage.py makemigrations APP_NAME = C:\repo_git\cmdb\gitee\cmdb (0.000) SELECT @@SQL_AUTO_IS_NULL; args=None (0.000) SELECT VERSION(); args=None (0.001) None; args=('read_all',) Traceback (most recent call last): File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params) File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute return self.cursor.execute(query, args) File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\cursors.py", line 209, in execute res = self._query(query) File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\cursors.py", line 315, in _query db.query(q) File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\connections.py", line 239, in query _mysql.connection.query(self, query) MySQLdb._exceptions.ProgrammingError: (1146, "Table 'cmdb.mgmt_permission' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "manage.py", line 32, in
execute_from_command_line(sys.argv)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management__init.py", line 364, in execute_from_command_line
utility.execute()
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management__init.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, cmd_options)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management\base.py", line 327, in execute
self.check()
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(kwargs)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\urls\resolvers.py", line 256, in check
for pattern in self.url_patterns:
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\utils\functional.py", line 35, in get
res = instance.dict__[self.name] = self.func(instance)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\urls\resolvers.py", line 407, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\utils\functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\urls\resolvers.py", line 400, in urlconf_module
return import_module(self.urlconf_name)
File "C:\py_envs\cmdb-CdfGpvMc\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\repo_git\cmdb\gitee\cmdb\cmdb\urls.py", line 28, in
url(r'^api/v1/mgmt/', include("mgmt.urls")),
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\conf\urls__init.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "C:\py_envs\cmdb-CdfGpvMc\lib\importlib\init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\repo_git\cmdb\gitee\cmdb\apps\mgmt\urls.py", line 3, in
from . import views
File "C:\repo_git\cmdb\gitee\cmdb\apps\mgmt\views.py", line 32, in
from . import initialize
File "C:\repo_git\cmdb\gitee\cmdb\apps\mgmt\initialize.py", line 124, in
permission, is_new = models.Permission.objects.get_or_create(name="read_all")
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, kwargs)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\query.py", line 464, in get_or_create
return self.get(lookup), False
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\query.py", line 374, in get
num = len(clone)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\query.py", line 232, in len
self._fetch_all()
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\query.py", line 1121, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\query.py", line 53, in iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\sql\compiler.py", line 899, in execute_sql
raise original_exception
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\models\sql\compiler.py", line 889, in execute_sql
cursor.execute(sql, params)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\utils.py", line 94, in exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
return self.cursor.execute(query, args)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\cursors.py", line 209, in execute
res = self._query(query)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\cursors.py", line 315, in _query
db.query(q)
File "C:\py_envs\cmdb-CdfGpvMc\lib\site-packages\MySQLdb\connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'cmdb.mgmt_permission' doesn't exist")
ry _mysql.connection.query(self, query) django.db.utils.ProgrammingError: (1146, "Table 'cmdb.mgmt_permission' doesn't exist") `
我在尝试手动部署,之前,docker方式部署是ok的。
想问下,初始化数据库不能通过 python manage.py makemigrations 进行吗? 是不是只能 用docker命令初始化(sudo docker run -it --rm --link cmdb-db -e DB_HOST=cmdb-db -e ENV=PRO -e DB_PORT=3306 -e DB_USERNAME=root -e DB_PASSWORD=cmdbcmdb -e DB_NAME=cmdb mingmingtang/cmdb init-db)数据库?