Django-apscheduler的安装和报错解决

Django-apscheduler的安装后没有表格生成,重新迁移

1,CMD,查看已经执行的migrations

python manage.py showmigrations

2,重置 app=django_apscheduler

python manage.py migrate --fake django_apscheduler zero

再执行 python manage.py showmigrations,你会发现 文件前的 [x] 变成了[ ]

3,重新migrate

python manage.py migrate --fake-initial

output:

Operations to perform:

Apply all migrations: admin, auth, ciss_exhi, contenttypes, django_apscheduler, sessions

Running migrations:

Applying django_apscheduler.0001_initial... OK

Applying django_apscheduler.0002_auto_20180412_0758... OK

Applying django_apscheduler.0003_auto_20200716_1632... OK

Applying django_apscheduler.0004_auto_20200717_1043... OK

Applying django_apscheduler.0005_migrate_name_to_id... OK

Applying django_apscheduler.0006_remove_djangojob_name... OK

Applying django_apscheduler.0007_auto_20200717_1404... OK

Applying django_apscheduler.0008_remove_djangojobexecution_started... OK

Applying django_apscheduler.0009_djangojobexecution_unique_job_executions... OK

=================================================================

Django-apscheduler的安装后没有表格生成,重新迁移

1,新建app=scheduler

python manage.py startapp scheduler

2,将...\site-packages\django_apscheduler\models.py里的表格设置内容,全部复制到

app=scheduler 目录内的models.py,并且都改名,例如

DjangoJob 改名为 DjangoJob2

DjangoJobExecutionManager 改名为 DjangoJobExecutionManager2

否则,会报错:(models.E032) constraint name 'unique_job_executions' is not unique among models: django_apscheduler.DjangoJobExecution, scheduler.DjangoJobExecution.

DjangoJobExecution 改名为DjangoJobExecution2

否则会报错:(models.E032) constraint name 'unique_job_executions' is not unique among models: django_apscheduler.DjangoJobExecution, scheduler.DjangoJobExecution.

3,python manage.py makemigrations 迁移

Migrations for 'scheduler':

scheduler\migrations\0001_initial.py

  • Create model DjangoJob2

  • Create model DjangoJobExecution2

  • Create constraint unique_job_executions2 on model djangojobexecution2

4,python manage.py migrate

如果跳过3,会遇到Your models in app(s): 'scheduler' have changes that are not yet reflected in a migration, and so won't be applied.

Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

相关推荐
F1FJJ2 分钟前
Shield CLI v0.3.0:插件系统上线,首发 MySQL Web 管理
网络·数据库·网络协议·mysql·容器·golang
波波七4 分钟前
maven导入spring框架
数据库·spring·maven
深蓝轨迹5 分钟前
Redis 分布式锁实现流程
数据库·redis·分布式
程序猿阿伟7 分钟前
《OpenClaw端口通信失效全解:监听修改与防火墙规则落地指南》
服务器·数据库·windows
进击的雷神7 分钟前
突破增量抓取困境:基于数据库状态判断的高效新闻爬虫设计
数据库·爬虫·spiderflow
一叶飘零_sweeeet12 分钟前
击穿 MySQL 事务隔离级别:底层实现原理 + 生产级架构选型避坑指南
数据库·mysql·架构·mysql事务隔离级别
虾..14 分钟前
Linux 五种IO模型
linux·服务器·数据库
程序边界20 分钟前
深度Oracle替换工程实践的技术解读(上篇)
数据库·oracle
2401_8318249628 分钟前
RESTful API设计最佳实践(Python版)
jvm·数据库·python
zjeweler29 分钟前
redis_tools_gui_v1.2 —Redis图形化漏洞利用工具
数据库·redis·web安全·缓存·安全性测试