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.

相关推荐
高兴就好(石2 小时前
DB-GPT部署和试用
数据库·gpt
这孩子叫逆2 小时前
6. 什么是MySQL的事务?如何在Java中使用Connection接口管理事务?
数据库·mysql
Karoku0662 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
码农郁郁久居人下3 小时前
Redis的配置与优化
数据库·redis·缓存
MuseLss4 小时前
Mycat搭建分库分表
数据库·mycat
Hsu_kk4 小时前
Redis 主从复制配置教程
数据库·redis·缓存
DieSnowK4 小时前
[Redis][环境配置]详细讲解
数据库·redis·分布式·缓存·环境配置·新手向·详细讲解
程序猿小D4 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
Flerken1014 小时前
数据库语言、SQL语言、数据库系统提供的两种语言
数据库·sql·oracle
掘根4 小时前
【网络】高级IO——poll版本TCP服务器
网络·数据库·sql·网络协议·tcp/ip·mysql·网络安全