我正在尝试使用 GeoDjango 创建一个数据库,但是当我尝试迁移数据库时,我得到“触发器 ISO_metadata_reference_row_id_value_insert 中的错误:没有这样的列:rowid”。我添加了正确的数据库引擎,并在
'django.contrib.gis',
中包含了 settings.py
。知道问题可能是什么吗?
from django.contrib.gis.db import models
# Create your models here.
class Bus(models.Model):
busID = models.IntegerField(primary_key=True)
route = models.CharField(max_length=20)
operator = models.SmallIntegerField()
latitude = models.DecimalField( max_digits=8, decimal_places=6)
longitude = models.DecimalField( max_digits=8, decimal_places=6)
location = models.PointField(srid=4326, blank=True, null=True)
updated = models.DateTimeField(blank=True, null=True)
lastStop = models.IntegerField(blank=True, null=True)
def __str__(self):
return self.busID
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
错误:
python3 ./manage.py migrate
Operations to perform:
Apply all migrations: admin, api, auth, contenttypes, sessions
Running migrations:
Applying admin.0002_logentry_remove_auto_add...Traceback (most recent call last):
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 357, in execute
return Database.Cursor.execute(self, query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: error in trigger ISO_metadata_reference_row_id_value_insert: no such column: rowid
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/vvv/Documents/Prosjekter/mqtt/./manage.py", line 22, in <module>
main()
File "/Users/vvv/Documents/Prosjekter/mqtt/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 349, in handle
post_migrate_state = executor.migrate(
^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/migrations/migration.py", line 130, in apply
operation.database_forwards(
File "/opt/homebrew/lib/python3.11/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py", line 173, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/base/schema.py", line 788, in alter_field
self._alter_field(
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py", line 460, in _alter_field
self._remake_table(model, alter_field=(old_field, new_field))
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py", line 347, in _remake_table
self.alter_db_table(
File "/opt/homebrew/lib/python3.11/site-packages/django/contrib/gis/db/backends/spatialite/schema.py", line 153, in alter_db_table
super().alter_db_table(model, old_db_table, new_db_table, disable_constraints)
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py", line 120, in alter_db_table
super().alter_db_table(model, old_db_table, new_db_table)
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/base/schema.py", line 606, in alter_db_table
self.execute(
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/base/schema.py", line 199, in execute
cursor.execute(sql, params)
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/opt/homebrew/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 357, in execute
return Database.Cursor.execute(self, query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: error in trigger ISO_metadata_reference_row_id_value_insert: no such column: rowid
我尝试删除旧的迁移,更新到最新版本的 Spatialite-tools。如果我删除模型中的所有字段,我仍然会收到错误消息。
我认为这对您的问题有帮助。 https://code.djangoproject.com/ticket/32935 https://groups.google.com/g/spatialite-users/c/SnNZt4AGm_o 如果这解决了您的问题,请分享结果。