在 django 上进行迁移后无法迁移

     2023-02-24     294

关键词:

【中文标题】在 django 上进行迁移后无法迁移【英文标题】:Can't migrate after makemigrations on django 【发布时间】:2021-06-27 18:56:47 【问题描述】:

每个人。我是这个领域的新手。所以,在我完成了makemigrations之后。然后我迁移出现此错误代码。我尝试解决它但仍然卡住。请指导,我附上我的错误代码如下。

(venv) C:\Users\hp\Desktop\Taskly_App\src>python manage.py migrate
Operations to perform:
   Apply all migrations: admin, auth, contenttypes, house, oauth2_provider, sessions, social_django, task, users
Running migrations:
  Applying task.0002_auto_20210331_2329...Traceback (most recent call last):
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: table "task_tasklist" already exists

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\migrations\operations\models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\base\schema.py", line 324, in create_model
    self.execute(sql, params or None)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return executor(sql, params, many, context)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "C:\Users\hp\Desktop\Taskly_App\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: table "task_tasklist" already exists

我不知道 task_tasklist 错误是什么意思。

请帮帮我!!

【问题讨论】:

这能回答你的问题吗? django 1.7 migrate gets error "table already exists" 【参考方案1】:

错误信息不言自明:

我们的数据库中已经存在表“task_tasklist”

【讨论】:

非常感谢您的指导。

Django迁移:关系不存在

】Django迁移:关系不存在【英文标题】:Djangomigrations:relationdoesnotexist【发布时间】:2017-07-0106:43:20【问题描述】:我的开发服务器上有一个工作站点和数据库,我正在尝试在实时服务器上进行设置。我正在执行以下操作:Git将... 查看详情

Django - 迁移后未创建表

】Django-迁移后未创建表【英文标题】:Django-Tableisnotcreatingaftermigration【发布时间】:2021-01-2101:00:24【问题描述】:我想在DigitalOcean服务器上使用Postgres数据库为我的Django项目添加新功能。问题是,在本地服务器上一切正常,但在... 查看详情

Django:合并迁移冲突的最佳方法

】Django:合并迁移冲突的最佳方法【英文标题】:Django:Bestwaytomergemigrationsconflicts【发布时间】:2018-04-1606:36:42【问题描述】:我目前正在开发一个dev分支,有一天我需要将它合并到master。我的dev分支上最多有20个迁移文件,而mas... 查看详情

如何在压缩它们后删除 django 迁移?

】如何在压缩它们后删除django迁移?【英文标题】:Howtodeletedjangomigrationsaftersquashingthem?【发布时间】:2015-08-1810:10:52【问题描述】:Django文档说我们可以在压缩迁移后删除它们:您应该提交此迁移,但保留旧迁移;这新迁移将... 查看详情

MongoDB 和 Artisan 在 Laravel 5 和 Lumen 上进行迁移

】MongoDB和Artisan在Laravel5和Lumen上进行迁移【英文标题】:MongoDBandArtisanMakeMigrationonLaravel5andLumen【发布时间】:2016-03-2213:09:51【问题描述】:正如标题所说,有没有一种方法可以使用Laravel的Artisan命令生成迁移脚本?【问题讨论】... 查看详情

Django迁移在Heroku上无法正常工作[重复]

】Django迁移在Heroku上无法正常工作[重复]【英文标题】:DjangomigrationnotworkingproperlyonHeroku[duplicate]【发布时间】:2021-12-0209:40:28【问题描述】:我在3个月前部署了一个Django应用程序,我能够在herokubash上轻松迁移更改。现在我正在... 查看详情

Django迁移RunPython无法调用模型方法

】Django迁移RunPython无法调用模型方法【英文标题】:DjangomigrationsRunPythonnotabletocallmodelmethods【发布时间】:2015-04-3021:20:32【问题描述】:我正在使用RunPython方法创建数据迁移。但是,当我尝试在对象上运行方法时,没有定义任何... 查看详情

.env 文件中的环境变量在 django、heroku 的本地迁移期间不可用

】.env文件中的环境变量在django、heroku的本地迁移期间不可用【英文标题】:Environmentalvariablesfrom.envfilenotavailableduringlocalmigrationsindjango,heroku【发布时间】:2016-11-2102:06:15【问题描述】:我一直在Heroku上进行开发,使用config变量来... 查看详情

Django ProgrammingError:在 Django 源代码中创建迁移后,关系已经存在?

】DjangoProgrammingError:在Django源代码中创建迁移后,关系已经存在?【英文标题】:DjangoProgrammingError:relationalreadyexistsafteramigrationcreatedintheDjangosourcecode?【发布时间】:2018-10-0608:38:33【问题描述】:我最近检查了一个项目的master分... 查看详情

Django 1.8 迁移无法将列 ID 转换为整数

】Django1.8迁移无法将列ID转换为整数【英文标题】:Django1.8migrationunabletocastcolumnidtointeger【发布时间】:2015-09-0601:00:07【问题描述】:我正在将我的网站从SQLite后端迁移到Postgres后端。从项目一开始,我们就一直在运行原生Django风... 查看详情

使用 --fake 后如何在 django 1.8 上重做迁移

】使用--fake后如何在django1.8上重做迁移【英文标题】:Howtoredoamigrationondjango1.8afterusing--fake【发布时间】:2015-08-1801:32:06【问题描述】:我的迁移出了点问题,我向模型添加了一个新的日期时间字段,然后我使用了makemigrations并进... 查看详情

Django 无法迁移内容类型迁移

】Django无法迁移内容类型迁移【英文标题】:Djongofailstomigratecontenttypesmigrations【发布时间】:2021-09-0815:18:11【问题描述】:我在我的项目中使用djongo进行MongoDB连接。我已经清理了所有以前的迁移,删除了sqlite数据库并再次为应... 查看详情

Django 无法迁移到新数据库

】Django无法迁移到新数据库【英文标题】:Djangocan\'tmigratetoanewdb【发布时间】:2021-12-2012:05:18【问题描述】:我创建了一个新的postgreSQL数据库并在没有迁移文件的Django项目上运行“pythonmanage.pymigrate”。出现了这个错误:django.db.... 查看详情

Heroku 不会在 Django 上迁移模型

】Heroku不会在Django上迁移模型【英文标题】:HerokudoesntmigratemodelsonDjango【发布时间】:2021-11-2912:47:46【问题描述】:我只是将我的Django应用程序部署到Heroku,但我无法将我的迁移迁移到Heroku。首先我运行:herokurunpythonmanage.pymigrat... 查看详情

即使在运行迁移后,Django Programming 错误列也不存在

】即使在运行迁移后,DjangoProgramming错误列也不存在【英文标题】:DjangoProgrammingerrorcolumndoesnotexistevenafterrunningmigrations【发布时间】:2017-07-2514:37:21【问题描述】:我运行pythonmanage.pymakemigrations并得到:未检测到更改然后,pythonma... 查看详情

在 Django 数据迁移中手动提交

】在Django数据迁移中手动提交【英文标题】:CommitmanuallyinDjangodatamigration【发布时间】:2015-09-2317:10:39【问题描述】:我想编写一个数据迁移,在其中我以较小的批量修改大表中的所有行,以避免锁定问题。但是,我不知道如何... 查看详情

无法使用 Django 3.0.3 中的迁移 API 使用 ModelState 和 ProjectState 进行迁移

】无法使用Django3.0.3中的迁移API使用ModelState和ProjectState进行迁移【英文标题】:UnabletomigrateusingModelStateandProjectStateusingofmigrationsAPIinDjango3.0.3【发布时间】:2021-02-1418:27:05【问题描述】:我正在使用ProjectState迁移到表的新属性。我... 查看详情

Django:在还原(迁移)后尝试访问数据库时权限被拒绝

】Django:在还原(迁移)后尝试访问数据库时权限被拒绝【英文标题】:Django:permissiondeniedwhentryingtoaccessdatabaseafterrestore(migration)【发布时间】:2012-08-2707:35:42【问题描述】:我在本地开发服务器中有一个django1.4应用程序,其中包... 查看详情