I am trying to rename some models and fields that have names I do not like. I am using an mssql database. I have a very simple model. An example would look something like this:
class RootProblem(models.Model):
rootproblemid = models.AutoField(db_column="RootProblemID", primary_key=True)
description = models.CharField(
db_column="Root Problems", unique=True, max_length=255, blank=False, null=True
)
I would like to rename the primary key from "rootproblemid" to something like "id". But when I change the name, run makemigrations, and then try to apply the new migration I get an error that says:
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "/usr/local/lib/python3.9/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 "/usr/local/lib/python3.9/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 "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 338, in database_forwards
schema_editor.alter_field(
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 571, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
File "/usr/local/lib/python3.9/site-packages/mssql/schema.py", line 282, in _alter_field
raise NotImplementedError("the backend doesn't support altering from/to %s." % t.__name__)
NotImplementedError: the backend doesn't support altering from/to AutoField.
I am able to change the names of all the other fields, but none of the primary key fields. Is this telling me that django doesn't support altering the name of an autofield for my backend? If so how would I get around this?