doccano how to upgrade 1.5.0 to 1.5.1

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

如何复现问题

# 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开发部分,并且遇到了相同的问题,后端发送了更多的日志:

backend_1   |   Applying api.0017_alter_example_id...Traceback (most recent call last):
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
backend_1   |     return self.cursor.execute(sql, params)
backend_1   | psycopg2.errors.CannotCoerce: cannot cast type integer to uuid
backend_1   | LINE 1: ...E "api_example" ALTER COLUMN "id" TYPE uuid USING "id"::uuid
backend_1   |                                                                  ^
backend_1   | 
backend_1   | 
backend_1   | The above exception was the direct cause of the following exception:
backend_1   | 
backend_1   | Traceback (most recent call last):
backend_1   |   File "/src/backend/manage.py", line 15, in <module>
backend_1   |     execute_from_command_line(sys.argv)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
backend_1   |     utility.execute()
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
backend_1   |     self.fetch_command(subcommand).run_from_argv(self.argv)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
backend_1   |     self.execute(*args, **cmd_options)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
backend_1   |     output = self.handle(*args, **options)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
backend_1   |     res = handle_func(*args, **kwargs)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
backend_1   |     post_migrate_state = executor.migrate(
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
backend_1   |     state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
backend_1   |     state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
backend_1   |     state = migration.apply(state, schema_editor)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/migration.py", line 126, in apply
backend_1   |     operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 244, in database_forwards
backend_1   |     schema_editor.alter_field(from_model, from_field, to_field)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 608, in alter_field
backend_1   |     self._alter_field(model, old_field, new_field, old_type, new_type,
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/schema.py", line 196, in _alter_field
backend_1   |     super()._alter_field(
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 765, in _alter_field
backend_1   |     self.execute(
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 145, in execute
backend_1   |     cursor.execute(sql, params)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
backend_1   |     return super().execute(sql, params)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
backend_1   |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
backend_1   |     return executor(sql, params, many, context)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
backend_1   |     return self.cursor.execute(sql, params)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
backend_1   |     raise dj_exc_value.with_traceback(traceback) from exc_value
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
backend_1   |     return self.cursor.execute(sql, params)
backend_1   | django.db.utils.ProgrammingError: cannot cast type integer to uuid
backend_1   | LINE 1: ...E "api_example" ALTER COLUMN "id" TYPE uuid USING "id"::uuid
backend_1   |                                                                  ^
backend_1   |

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

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

mlmc2os52#

export DATABASE_URL=postgres://
 database:postgres
dkqlctbz

dkqlctbz3#

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

class Example(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True) # This one
    meta = models.JSONField(default=dict)
    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:

--- a/backend/api/migrations/0012_auto_20210514_0654.py
+++ b/backend/api/migrations/0012_auto_20210514_0654.py
@@ -3,6 +3,7 @@
 from django.conf import settings
 from django.db import migrations, models
 import django.db.models.deletion
+import uuid
 
 
 class Migration(migrations.Migration):
@@ -26,7 +27,7 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name='Example',
             fields=[
-                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                 ('meta', models.JSONField(default=dict)),
                 ('filename', models.FileField(default='.', upload_to='')),
                 ('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下运行已存在的数据库。

相关问题