While attempting to migrate database changes using django on Heroku, I get:
psycopg2.ProgrammingError: permission denied for relation django_migrations
Other people have been able to resolve this issue by granting the appropriate privileges (e.g., Permission denied for relation). Unfortunately, I can't grant permissions or create a new user on the Heroku hobby tier.
I was able to roll back a few migrations, but eventually I got:
django.db.utils.ProgrammingError: table "labs_branch_tests" does not exist
and could not migrate back to newer migrations.
Full traceback for permission denied for relation django_migrations
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/app/.heroku/python/lib/python3.6/site-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 "/app/.heroku/python/lib/python3.6/site-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 "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 250, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in record_applied
self.migration_qs.create(app=app, name=name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
obj.save(force_insert=True, using=self.db)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save
force_update=force_update, update_fields=update_fields)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 923, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 962, in _do_insert
using=using, raw=raw)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1107, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: permission denied for relation django_migrations
Full traceback for psycopg2.ProgrammingError: table "labs_branch_tests" does not exist
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 119, in migrate
state = self._migrate_all_backwards(plan, full_plan, fake=fake)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 194, in _migrate_all_backwards
self.unapply_migration(states[migration], migration, fake=fake)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 264, in unapply_migration
state = migration.unapply(state, schema_editor)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/migration.py", line 178, in unapply
operation.database_backwards(self.app_label, schema_editor, from_state, to_state)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 95, in database_backwards
schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 457, in remove_field
return self.delete_model(field.remote_field.through)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 324, in delete_model
"table": self.quote_name(model._meta.db_table),
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 120, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: table "labs_branch_tests" does not exist
I was able to get around this by granting privileges to the user in the postgres terminal.
First connect to postgres through the Heroku CLI (heroku pg:psql).
This is clunky but get your Heroku postgres username by calling \c in the postgres terminal. (The last line of output will be You are now connected to database DATABASE_NAME as user USERNAME.)
Then grant privileges as others have shown:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to USERNAME;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public to USERNAME;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public to USERNAME;
In my case this was because my free database reached its row limit and write access was revoked:
$ heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.4
[..]
Rows: 11683/10000 (Write access revoked)
[..]
for me yes you can tell the write access was revoked with
$ heroku pg:info
...
Rows: 11683/10000 (Write access revoked)
but I didn't want to dump the whole database. Instead I identify the biggest tables with
$ heroku pg:psql
> select
table_name
, pg_relation_size(quote_ident(table_name)) as "raw_size"
, pg_size_pretty(pg_relation_size(quote_ident(table_name)) as "size"
from information_schema.tables
where table_schema = 'public'
order by "raw_size" desc;
and then I clear the biggest tables with
> delete from <table name>;
Related
I'm setting up a database in django, while trying to flush the database i get the following error:
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the "/home/luc/projects/PySorge/API/db.sqlite3" database,
and return each table to an empty state.
Are you sure you want to do this?
Type yes to continue, or no to cancel: yes
Traceback (most recent call last):
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: django_content_type.name
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/luc/projects/PySorge/API/manage.py", line 22, in <module>
main()
File "/home/luc/projects/PySorge/API/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/luc/.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 "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/commands/flush.py", line 80, in handle
emit_post_migrate_signal(verbosity, interactive, database)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/sql.py", line 48, in emit_post_migrate_signal
models.signals.post_migrate.send(
File "/home/luc/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 177, in send
return [
File "/home/luc/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/home/luc/.local/lib/python3.9/site-packages/django/contrib/auth/management/__init__.py", line 42, in create_permissions
create_contenttypes(app_config, verbosity=verbosity, interactive=interactive, using=using, apps=apps, **kwargs)
File "/home/luc/.local/lib/python3.9/site-packages/django/contrib/contenttypes/management/__init__.py", line 132, in create_contenttypes
ContentType.objects.using(using).bulk_create(cts)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 506, in bulk_create
returned_columns = self._batched_insert(
File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 1277, in _batched_insert
self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: django_content_type.name
While trying to migrate, the following error occured:
Operations to perform:
Apply all migrations: admin, api, auth, contenttypes, sessions
Running migrations:
Applying api.0001_initial...Traceback (most recent call last):
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: duplicate column name: ID
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/luc/projects/PySorge/API/manage.py", line 22, in <module>
main()
File "/home/luc/projects/PySorge/API/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/luc/.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 "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "/home/luc/.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 "/home/luc/.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 "/home/luc/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/luc/.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 "/home/luc/.local/lib/python3.9/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 324, in create_model
self.execute(sql, params or None)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 142, in execute
cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: duplicate column name: ID
I'm using django version 3.1.6. I'm not really sure how to fix this as I'm not very familiar with databases. Seems like the error is caused by a duplicate field id - my current database setup does have a field named ID.
My recommendation, although certainly not the best way forward, would be to delete the database (delete the actual sqlite3 file in your project) then delete all of your previous migrations, and then try making migrations again.
I had a very old Django site (still had South migrations in tree!) that had been ticking along on a SQLite database forever. At some point Django removed the name column from the django_content_types table. The model uses a property now based on the reflected model class. I've no idea why this hadn't be caught by a Django migration, but I've been known to fake migrations in the blood mist of getting something to run, no-matter-what.
I just dropped the column in ./manage.py dbshell:
ALTER TABLE django_content_type DROP COLUMN name;
And migrations worked again. No ill effects felt. All my old contenttypes are in there, everything still works.
python manage.py reset_db
This will delete all tables. It also helps to delete all migration files in the project if you want a complete wipeout
I am not able to migrate project in linux. Dependecy:cx-Oracle==7.2.0
Django==1.11,oracle11g and python3.I am trying to connect with a server database.
I removed a line self.cursor.numbersAsStrings = True from /work/sunlife_env/lib/python3.6/site-packages/django/db/backends/oracle/base.py to resolve this error:
AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'
BUT now, after python manage.py migrate, I am getting the following error.
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/arima/work/sunlife_env/lib/python3.6/site-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 "/home/arima/work/sunlife_env/lib/python3.6/site-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 "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/migrations/executor.py", line 250, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in record_applied
self.migration_qs.create(app=app, name=name)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/query.py", line 393, in create
obj.save(force_insert=True, using=self.db)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/base.py", line 806, in save
force_update=force_update, update_fields=update_fields)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/base.py", line 836, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/base.py", line 922, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/base.py", line 961, in _do_insert
using=using, raw=raw)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/query.py", line 1060, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1106, in execute_sql
return self.connection.ops.fetch_returned_insert_id(cursor)
File "/home/arima/work/sunlife_env/lib/python3.6/site-packages/django/db/backends/oracle/operations.py", line 245, in fetch_returned_insert_id
return int(cursor._insert_id_var.getvalue())
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
I need help to connect my db to django project.
I am getting a migrate command error --
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'module_name' used in key specification without a key length")
The model is
class Coupling(models.Model):
coupling_name = models.CharField(max_length=150, blank=False, default=True, unique=True)
module_name = models.TextField(max_length=255)
There is a key length though.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\virtualenvs\ciasenv\lib\site-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 "C:\virtualenvs\ciasenv\lib\site-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 "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\operations\fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 678, in _alter_field
self.execute(self._create_unique_sql(model, [new_field.column]))
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 112, in execute
cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\mysql\base.py", line 112, in execute
return self.cursor.execute(query, args)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1061, "Duplicate key name 'accounts_coupling_coupling_name_175325e1_uniq'")
Any help is highly appreciated. Thanks in advance.
The first error might be because you tried to set unique=True for the TextField. This is not possible for MySQL, as noted in the docs.
The second error is because you are trying to create an index that already exists. This could be because you already ran the migration and it failed part way through. MySQL does not run schema changes in a transaction, so changes aren't rolled back if they fail. You could try dropping the index manually, or, if this is a new project, it might be easier to drop the database and start again.
I have spent hours trying to get a vagrant django development environment running on my Windows 7 machine.
So far I have:
Used vagrant to create an ubuntu vm
Installed python 3.4.3
Installed mariadb 5.5
Installed django 1.9
Installed mysql-connector-python 2.1.3
Created a new DB in mysql
On a fresh django install, when I try to run python manage.py migrate, I get the following error:
Operations to perform:
Apply all migrations: sessions, auth, contenttypes, admin
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
return method(query, args)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 515, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 434, in _handle_result
self._handle_noresultset(result)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 404, in _handle_noresultset
self._warnings[0][1], self._warnings[0][2])
mysql.connector.errors.DatabaseError: 1265: Data truncated for column 'applied' at row 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 204, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 73, in record_applied
self.migration_qs.create(app=app, name=name)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/base.py", line 700, in save
force_update=force_update, update_fields=update_fields)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/base.py", line 728, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/base.py", line 812, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/base.py", line 851, in _do_insert
using=using, raw=raw)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 1064, in execute_sql
cursor.execute(sql, params)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/django/base.py", line 227, in execute
return self._execute_wrapper(self.cursor.execute, query, new_args)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/django/base.py", line 195, in _execute_wrapper
utils.DatabaseError(err.msg), sys.exc_info()[2])
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
return method(query, args)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 515, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 434, in _handle_result
self._handle_noresultset(result)
File "/home/vagrant/djangoenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 404, in _handle_noresultset
self._warnings[0][1], self._warnings[0][2])
django.db.utils.DatabaseError: Data truncated for column 'applied' at row 1
I couldn't find anything that had that exact error. Anyone have any ideas?
It turns out the issue isn't how the table or column is defined, so just looking at the table or column definitions isn't going to do you any good*.
In your [project_name]/settings.py file make sure that under ...
DATABASES = { ...
... the ENGINE attribute is set to django.db.backends.mysql as opposed to mysql.connector.django.
*Although, you should make sure that the column type for applied is DATETIME(6), which shouldn't be a problem since that's the default value Django gives it, so unless you somehow changed it, you should be fine.
The table is django_migrations in case you are wanting to look up the data type.
If you store 12345678901234567890 into an INT, it will be truncated.
If you store 'asdfasdfasdf' into VARCHAR(5), it will be truncated.
Look at your table definition and your data. You can figure this out.
I'm trying to set up django-notifications in my app. I'm following the instructions to install it, which are pretty straight-forward: https://github.com/brantyoung/django-notifications#installation
When I run manage.py migrate notifications I get:
django.db.utils.ProgrammingError: (1146, "Table '{{database}}.notifications_notification' doesn't exist")
I'm at a loss.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 230, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 305, in migrate_many
result = self.migrate(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 134, in migrate
result = self.run(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 115, in run
return self.run_migration(migration, database)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 85, in run_migration
migration_function()
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/migration/migrators.py", line 61, in <lambda>
return (lambda: direction(orm))
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/notifications/migrations/0002_auto__add_field_notification_data.py", line 14, in forwards
keep_default=False)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 47, in _cache_clear
return func(self, table, *args, **opts)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 418, in add_column
self.execute(sql)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/south/db/generic.py", line 282, in execute
cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute
self.errorhandler(self, exc, value)
File "/Users/nicholsp/.virtualenvs/ownership/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.ProgrammingError: (1146, "Table 'ownershipdb.notifications_notification' doesn't exist")
You forget to run syncdb before migrating data. The table doesn't exists because it's syncdb that created it, not the migration.
Reference: http://south.readthedocs.org/en/latest/tutorial/part1.html
(If this fails complaining that south_migrationhistory does not exist, you forgot to run syncdb after you installed South.)