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.

相关推荐
摇滚侠7 分钟前
全面掌握PostgreSQL关系型数据库,设置远程连接,笔记05,笔记06
java·数据库·笔记·postgresql
mpHH9 分钟前
postgresql plancache --doing
数据库·学习·postgresql·1024程序员节
布朗克16811 分钟前
MySQL 运算符详细说明
数据库·mysql·运算符·1024程序员节
机灵猫41 分钟前
微服务中的服务熔断、降级与限流
java·数据库·微服务
言德斐44 分钟前
Python Web框架深度对比:Django vs Flask vs FastAPI(含优缺点与选型策略)
前端·python·django
枫叶丹41 小时前
破局政务数字化核心难题:金仓数据库以国产化方案引领电子证照系统升级之路
数据库·政务·1024程序员节·金仓
托比-马奎尔1 小时前
Redis主从集群
数据库·redis·缓存
belldeep1 小时前
python:怎样用 Django 开发电子商务程序
django·电子商务·1024程序员节
码力引擎2 小时前
【零基础学MySQL】第一章:MySQL介绍与安装
数据库·mysql·1024程序员节
小超嵌入式笔记2 小时前
【Keil5教程及技巧】耗时一周精心整理万字全网最全Keil5(MDK-ARM)功能详细介绍【建议收藏-细细品尝】
java·数据库·mongodb