Reputation: 2036
Can you help?
I made a mistake on my Django models.py and wanted to then delete the model.
As you can see from the below, the migration was to delete the model called code.
However, it still errors & doesn't delete the model.
What can I do?
root@new:/home/django/django_project# python manage.py makemigrations
Migrations for 'netshock':
netshock/migrations/0018_delete_code.py
- Delete model code
root@new:/home/django/django_project# python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, netshock, sessions
Running migrations:
Applying netshock.0012_code...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 97, in database_forwards
schema_editor.create_model(model)
File "/usr/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 303, in create_model
self.execute(sql, params or None)
File "/usr/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 120, in execute
cursor.execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: syntax error at or near "4000000000"
LINE 1: ...("id" serial NOT NULL PRIMARY KEY, "code" varchar(4000000000...
Upvotes: 1
Views: 64
Reputation: 477686
The problem is specified at the bottom of the error:
django.db.utils.ProgrammingError: syntax error at or near "4000000000" LINE 1: ...("id" serial NOT NULL PRIMARY KEY, "code" varchar(4000000000...
Now 4000000000
is simply too large. PostgreSQL mentions that the maximum size of character types is 1GB [PostgreSQL-doc]:
(...) In any case, the longest possible character string that can be stored is about 1 GB. (The maximum value that will be allowed for n in the data type declaration is less than that. It wouldn't be useful to change this because with multibyte character encodings the number of characters and bytes can be quite different. If you desire to store long strings with no specific upper limit, use text or character varying without a length specifier, rather than making up an arbitrary length limit.)
So setting this to 4'000'000'000 makes no sense.
If you later make extra changes, this will not resolve the issue (at least not immediately), since you created migration files with the 4000000000
in these. You will have to remove the migration files that can not be applied (together with the ones that follow on these migrations, since otherwise there is likely an error in the chain), and make new migration files.
Upvotes: 1