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 小时前
OpenClaw 深度解析:从原理到实战的完整指南
运维·服务器·数据库·github·copilot
hzp6667 小时前
doris学习6:参数调优
数据库·doris·参数·数据库调优
盟道科技8 小时前
小程序电商订单超时自动取消的三种实现方案:定时扫描、Redis 过期监听、延迟消息对比与生产落地
数据库·redis·小程序
剑锋所指,所向披靡!8 小时前
MySQL存储引擎
数据库·mysql
reasonsummer8 小时前
【办公类-146-05】20260901《一分园、二分园四大教育》(优化版:标题excle+复制AI文字+Python占位符录入)
开发语言·数据库·c#
2301_800954998 小时前
关系型数据库与非关系型数据库详解
数据库·nosql
崖边看雾8 小时前
MySQL——SQL 经典练习题:学生选课成绩查询(附详细注释)
大数据·数据库·sql·mysql
众壹新能源科技8 小时前
经营口径与运维口径不一致时,发电量报表怎么对账
运维·数据库·人工智能
jyOverQ9 小时前
MySQL 索引为什么能加快查询?B+Tree 到底是什么?
数据库·mysql
天天进步20159 小时前
Pixelle-Video 源码解析 #17:TTS 语音生成:Edge-TTS、Index-TTS 如何接入?
前端·数据库