运行migrate 报错

来源:4-5 删改部分文件完成项目初始模板

郑天

2022-11-13

图片描述
manage.py@zanhu > migrate
ssh://root@/root/.local/share/virtualenvs/zanhu-OW0Grnnx/bin/python -u /root/.pycharm_helpers/pycharm/django_manage.py migra](http://img.mukewang.com/szimg/6370da1c088572d203740377.jpg)/root/devel/zanhu
File tracking disabled
Operations to perform:
Apply all migrations: account, auth, contenttypes, django_celery_beat, sessions, sites, socialaccount, users
Running migrations:
Applying sites.0003_set_site_domain_and_name…Traceback (most recent call last):
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/mysql/base.py”, line 73, in execute
return self.cursor.execute(query, args)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/cursors.py”, line 312, in _query
db.query(q)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/connections.py”, line 224, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, “Table ‘zanhu02.django_site_id_seq’ doesn’t exist”)

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

Traceback (most recent call last):
File “/root/.pycharm_helpers/pycharm/django_manage.py”, line 59, in
run_command()
File “/root/.pycharm_helpers/pycharm/django_manage.py”, line 46, in run_command
run_module(manage_file, None, ‘main’, True)
File “/usr/local/python3/lib/python3.7/runpy.py”, line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File “/usr/local/python3/lib/python3.7/runpy.py”, line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File “/usr/local/python3/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/root/devel/zanhu/manage.py”, line 31, in
execute_from_command_line(sys.argv)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/init.py”, line 419, in execute_from_command_line
utility.execute()
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/init.py”, line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/base.py”, line 354, in run_from_argv
self.execute(*args, **cmd_options)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/base.py”, line 398, in execute
output = self.handle(*args, **options)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/base.py”, line 89, in wrapped
res = handle_func(*args, **kwargs)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/core/management/commands/migrate.py”, line 246, in handle
fake_initial=fake_initial,
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/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 “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/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 “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/migrations/executor.py”, line 227, in apply_migration
state = migration.apply(state, schema_editor)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/migrations/migration.py”, line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/migrations/operations/special.py”, line 190, in database_forwards
self.code(from_state.apps, schema_editor)
File “/root/devel/zanhu/zanhu/contrib/sites/migrations/0003_set_site_domain_and_name.py”, line 44, in update_site_forward
"zanhu",
File “/root/devel/zanhu/zanhu/contrib/sites/migrations/0003_set_site_domain_and_name.py”, line 28, in _update_or_create_site_with_sequence
cursor.execute(“SELECT last_value from django_site_id_seq”)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 98, in execute
return super().execute(sql, params)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/django/db/backends/mysql/base.py”, line 73, in execute
return self.cursor.execute(query, args)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/cursors.py”, line 206, in execute
res = self._query(query)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/cursors.py”, line 312, in _query
db.query(q)
File “/root/.local/share/virtualenvs/zanhu-OW0Grnnx/lib/python3.7/site-packages/MySQLdb/connections.py”, line 224, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, “Table ‘zanhu02.django_site_id_seq’ doesn’t exist”)

进程已结束,退出代码1

写回答

3回答

郑天

提问者

2022-11-13

//img.mukewang.com/szimg/6370da1c088572d200000000.jpg

这个数据库表

1
1
Jack
解决了么?平时没上来看问题了。。。抱歉
2022-11-26
共1条回复

python搬运工

2022-11-16

可以参考一下https://coding.imooc.com/learn/questiondetail/GgzqwPj5z3p6DxW0.html

0
1
郑天
感谢,感谢。这个方法没试过,我是删除对应的文件,和清理数据库表重新生成就成功了
2022-11-17
共1条回复

郑天

提问者

2022-11-13

....

0
0

Django高级实战 开发企业级问答网站

融合Django高级用法/算法/设计模式/TestCase测试/云计算打造项目

900 学习 · 756 问题

查看课程