django-libsql icon indicating copy to clipboard operation
django-libsql copied to clipboard

Migration Error

Open buffmomoeveryday opened this issue 1 year ago • 5 comments

Applying admin.0002_logentry_remove_auto_add...Traceback (most recent call last): File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/src/manage.py", line 22, in main() File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/src/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/init.py", line 442, in execute_from_command_line utility.execute() File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/init.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv self.execute(*args, **cmd_options) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/base.py", line 459, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper res = handle_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/core/management/commands/migrate.py", line 357, in handle post_migrate_state = executor.migrate( ^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( ^^^^^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/migrations/executor.py", line 255, in apply_migration state = migration.apply(state, schema_editor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/migrations/operations/fields.py", line 241, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/libsql/db/backends/sqlite3/schema.py", line 173, in alter_field super().alter_field(model, old_field, new_field, strict=strict) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/django/db/backends/base/schema.py", line 905, in alter_field self._alter_field( File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/libsql/db/backends/sqlite3/schema.py", line 461, in _alter_field self._remake_table(model, alter_fields=[(old_field, new_field)]) File "/home/siddharthakhanal/Desktop/rocky-dai/silkhair-track/venv/lib64/python3.12/site-packages/libsql/db/backends/sqlite3/schema.py", line 279, in _remake_table for index in model._meta.index_together ^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Options' object has no attribute 'index_together'. Did you mean: 'unique_together'?

buffmomoeveryday avatar Oct 15 '24 08:10 buffmomoeveryday

i have the same error

eljoe182 avatar Nov 05 '24 02:11 eljoe182

Facing the same error

xeroticikot avatar Nov 12 '24 03:11 xeroticikot

Same here.

trey avatar Nov 23 '24 14:11 trey

(Please comment with additional information to help solve the actual issue.)

I was able to migrate the database in Django 5.0 but this error occurred in Django 5.1+ during the initial migration.

Here's a complete log on my environment:

Preparation

Launched the local dev server with turso CLI command:

> turso dev
sqld listening on port 8080.
Use the following URL to configure your libSQL client SDK for local development:

    http://127.0.0.1:8080

By default, no auth token is required when sqld is running locally. If you want to require authentication, use --auth-jwt-key-file to specify a file containing the JWT key.

This server is using an ephemeral database. Changes will be lost when this server stops.
If you want to persist changes, use --db-file to specify a SQLite database file instead.

Updated settings.py to use local libSQL server:

...
DATABASES = {

    "default": {
        "ENGINE": "libsql.db.backends.sqlite3",
        "NAME": "ws://localhost:8080"
    }
}
...

Migration on Django 5.1+

> ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add...Traceback (most recent call last):
  File "/home/shuuji3/dev/django_libsql_playground/./manage.py", line 22, in <module>
    main()
  File "/home/shuuji3/dev/django_libsql_playground/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 357, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
    state = migration.apply(state, schema_editor)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/migrations/operations/fields.py", line 241, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/libsql/db/backends/sqlite3/schema.py", line 173, in alter_field
    super().alter_field(model, old_field, new_field, strict=strict)
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/django/db/backends/base/schema.py", line 905, in alter_field
    self._alter_field(
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/libsql/db/backends/sqlite3/schema.py", line 461, in _alter_field
    self._remake_table(model, alter_fields=[(old_field, new_field)])
  File "/home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages/libsql/db/backends/sqlite3/schema.py", line 279, in _remake_table
    for index in model._meta.index_together
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Options' object has no attribute 'index_together'. Did you mean: 'unique_together'?

After downgrading to Django 5.0

> pip install django'<5.1'
Collecting django<5.1
  Downloading Django-5.0.10-py3-none-any.whl.metadata (4.1 kB)
Requirement already satisfied: asgiref<4,>=3.7.0 in /home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages (from django<5.1) (3.8.1)
Requirement already satisfied: sqlparse>=0.3.1 in /home/shuuji3/.local/share/mise/installs/python/3.11.11/lib/python3.11/site-packages (from django<5.1) (0.5.3)
Downloading Django-5.0.10-py3-none-any.whl (8.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.2/8.2 MB 39.0 MB/s eta 0:00:00
Installing collected packages: django
  Attempting uninstall: django
    Found existing installation: Django 5.1.4
    Uninstalling Django-5.1.4:
      Successfully uninstalled Django-5.1.4
Successfully installed django-5.0.10

> ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

shuuji3 avatar Dec 29 '24 14:12 shuuji3

The index_together was deprecated in Django 4.2 and removed in Django 5.1 and its release note describes how to migrate:

  • Django 4.2 release notes | Django documentation | Django - https://docs.djangoproject.com/en/5.1/releases/4.2/#index-together-option-is-deprecated-in-favor-of-indexes

shuuji3 avatar Dec 30 '24 08:12 shuuji3