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.

相关推荐
羱滒3 分钟前
sql调优之数据库开发规范
java·数据库·数据库开发
程序员Android6 分钟前
MTK多帧拍照流程分析
数据库
不剪发的Tony老师7 分钟前
Apache Doris:一款高性能的实时数据仓库
数据库·数据仓库
甜可儿18 分钟前
redis序列化设置
数据库·redis
GGBondlctrl23 分钟前
【SpringBoot】论坛项目中如何进行实现发布文章,以及更新对应数据库的数据更新
数据库·springboot项目·三层设计思想·文章发布项目
若云止水37 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
jay丿1 小时前
Django模板系统深入
数据库·django·sqlite
千层冷面1 小时前
Redis除了做缓存还能做什么?
数据库·redis·缓存
码有余悸3 小时前
Redis:高性能的键值存储系统
数据库·redis·缓存
剑客狼心7 小时前
Oracle:什么是存储过程
数据库·oracle