doccano how to upgrade 1.5.0 to 1.5.1

cfh9epnr  于 8个月前  发布在  其他
关注(0)|答案(6)|浏览(113)

如何复现问题

  1. # copy-paste the error message here

您的环境

  • 操作系统:
  • 使用的Python版本:
  • 当您安装doccano时:
  • 您是如何安装doccano的(Heroku按钮等):

命令:
/home/workuser/.local/bin/doccano init
过程:
应用所有迁移
错误:
psycopg2.errors.CannotCoerce:无法将整数类型转换为uuid
行1: ...E "api_example" ALTER COLUMN "id" TYPE uuid USING "id"::uuid
^

vvppvyoh

vvppvyoh1#

Docker安装也遇到了同样的问题,我正在处理Docker开发部分,并且遇到了相同的问题,后端发送了更多的日志:

  1. backend_1 | Applying api.0017_alter_example_id...Traceback (most recent call last):
  2. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
  3. backend_1 | return self.cursor.execute(sql, params)
  4. backend_1 | psycopg2.errors.CannotCoerce: cannot cast type integer to uuid
  5. backend_1 | LINE 1: ...E "api_example" ALTER COLUMN "id" TYPE uuid USING "id"::uuid
  6. backend_1 | ^
  7. backend_1 |
  8. backend_1 |
  9. backend_1 | The above exception was the direct cause of the following exception:
  10. backend_1 |
  11. backend_1 | Traceback (most recent call last):
  12. backend_1 | File "/src/backend/manage.py", line 15, in <module>
  13. backend_1 | execute_from_command_line(sys.argv)
  14. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
  15. backend_1 | utility.execute()
  16. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
  17. backend_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
  18. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
  19. backend_1 | self.execute(*args, **cmd_options)
  20. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
  21. backend_1 | output = self.handle(*args, **options)
  22. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
  23. backend_1 | res = handle_func(*args, **kwargs)
  24. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
  25. backend_1 | post_migrate_state = executor.migrate(
  26. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
  27. backend_1 | state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  28. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
  29. backend_1 | state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  30. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
  31. backend_1 | state = migration.apply(state, schema_editor)
  32. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/migration.py", line 126, in apply
  33. backend_1 | operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  34. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 244, in database_forwards
  35. backend_1 | schema_editor.alter_field(from_model, from_field, to_field)
  36. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 608, in alter_field
  37. backend_1 | self._alter_field(model, old_field, new_field, old_type, new_type,
  38. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/schema.py", line 196, in _alter_field
  39. backend_1 | super()._alter_field(
  40. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 765, in _alter_field
  41. backend_1 | self.execute(
  42. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 145, in execute
  43. backend_1 | cursor.execute(sql, params)
  44. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
  45. backend_1 | return super().execute(sql, params)
  46. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
  47. backend_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  48. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
  49. backend_1 | return executor(sql, params, many, context)
  50. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
  51. backend_1 | return self.cursor.execute(sql, params)
  52. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
  53. backend_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
  54. backend_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
  55. backend_1 | return self.cursor.execute(sql, params)
  56. backend_1 | django.db.utils.ProgrammingError: cannot cast type integer to uuid
  57. backend_1 | LINE 1: ...E "api_example" ALTER COLUMN "id" TYPE uuid USING "id"::uuid
  58. backend_1 | ^
  59. backend_1 |

这可能是由于我刚刚收到的Celery警告引起的:

  1. celery_1 | /usr/local/lib/python3.8/site-packages/celery/platforms.py:834: SecurityWarning: You're running the worker with superuser privileges: this is
  2. celery_1 | absolutely not recommended!
  3. celery_1 |
  4. celery_1 | Please specify a different user using the --uid option.
  5. celery_1 |
  6. celery_1 | User information: uid=0 euid=0 gid=0 egid=0
  7. celery_1 |
  8. celery_1 | warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format(
展开查看全部
mlmc2os5

mlmc2os52#

  1. export DATABASE_URL=postgres://
  2. database:postgres
dkqlctbz

dkqlctbz3#

这是由于在backend/api/models.py(第153行)添加了以下代码:

  1. class Example(models.Model):
  2. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True) # This one
  3. meta = models.JSONField(default=dict)
  4. filename = models.FileField(default='.', max_length=1024)

我认为他们忘记在postgres数据库上重新应用迁移,导致了这个错误。

v7pvogib

v7pvogib4#

drop all database
vim 0012_auto_20210514_0654.py line 26 near "name='Example',"
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
to
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
or
('id', models.UUIDField(db_index=True, editable=False, primary_key=True, serialize=False)),
doccano init

sigwle7e

sigwle7e5#

Thanks @Shinku-Chen, worked pretty well for me. For docker user this file is stored under /backend/api/migrations/. Here is the git diff:

  1. --- a/backend/api/migrations/0012_auto_20210514_0654.py
  2. +++ b/backend/api/migrations/0012_auto_20210514_0654.py
  3. @@ -3,6 +3,7 @@
  4. from django.conf import settings
  5. from django.db import migrations, models
  6. import django.db.models.deletion
  7. +import uuid
  8. class Migration(migrations.Migration):
  9. @@ -26,7 +27,7 @@ class Migration(migrations.Migration):
  10. migrations.CreateModel(
  11. name='Example',
  12. fields=[
  13. - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
  14. + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
  15. ('meta', models.JSONField(default=dict)),
  16. ('filename', models.FileField(default='.', upload_to='')),
  17. ('text', models.TextField(blank=True, null=True)),
展开查看全部
9bfwbjaz

9bfwbjaz6#

我不确定在数据库环境下,从1.5.0升级到1.5.1的0017_alter_example_id.py是否有效。

0017_alter_example_id.py无法在Postgres下运行已存在的数据库。

相关问题