I recently had a database issue so I decided to nuke it since I had no important data. I deleted my migrations folder in my app directory and dropped the database. However now when I go to recreate everything with manage.py migrate I get the following error:
File "../manage.py", line 21, in <module>
main()
File "../manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 91, in migrate
self.recorder.ensure_schema()
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 69, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1050, "Table 'django_migrations' already exists"))
I have tried running this after deleting the database, and after recreating the empty database. I can be 100% sure there are no tables there right now. So I have no idea why it thinks that table is there.
Figured out my issue. MariaDB had my tables open in the cache. I ran two statements: FLUSH QUERY CACHE; and FLUSH TABLES;. I'm not sure which one did the trick but I was then able to run migrations and everything works again now!
Removed migrations and created the project directory and startapp directory again.
Then makemigration and migrate. Worked on mySQL.
Related
Heroko Config
DATABASE_URL: postgres://xxxxxxxx:xxxxxxxxxx#ec2-54-243-215-140.compute-1.amazonaws.com:5432/xxxxxxxxx
HEROKU_POSTGRESQL_GOLD_URL: postgres://yyyyyyyyyyy:yyyyyyyyyyyyy#ec2-54-243-243-20.compute-1.amazonaws.com:5432/yyyyyyyyyy
HEROKU_POSTGRESQL_YELLOW_URL: postgres://zzzzzzzzzz:zzzzzzzzzzzz#ec2-54-243-215-140.compute-1.amazonaws.com:5432/zzzzzzzzz
settings.py
DATABASES = {'default': dj_database_url.config(default='postgres://xxxxxxxx:xxxxxxxxxx#ec2-54-243-215-140.compute-1.amazonaws.com:5432/xxxxxxxxx'),}
heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.4673
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 60, in handle_noargs
tables = connection.introspection.table_names()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 910, in table_names
return self.get_table_list(cursor)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/introspection.py", line 33, in get_table_list
AND pg_catalog.pg_table_is_visible(c.oid)""")
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError: current transaction is aborted, commands ignored until end of transaction block
Many do not speak English and therefore can not explanation. What's the problem?
The error you have posted merely means that there was a previous error in the transaction and the transaction has already aborted. You cannot fix this problem by troubleshooting this error. You must find out what your real problem is and try to fix it.
To do this, check your PostgreSQL logs, and search backwards from this error until you come to a different error. That will be the error that terminated the transaction and you can work on fixing that one instead. This error however is meaningless from a troubleshooting perspective. Find your real problem and fix it.
I am learning Django, and this is my first project. I am working on this project in this tutorial. https://docs.djangoproject.com/en/1.4/intro/tutorial01/
when I ran syncdb command. tables were created. then it asked me if I want to add a superuser, I said yes. then got following error message. I found a few similar questions on stackoverflow, but still canot get it fixed.
(django)feelexit#ubuntu:~/.virtualenvs/testDjango$ ./manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): y
Please enter either "yes" or "no": yes
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 73, in create_superuser
call_command("createsuperuser", interactive=True, database=db)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 70, in handle
default_username = get_default_username()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username
default_username = get_system_username()
File "/home/feelexit/.virtualenvs/django/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 85, in get_system_username
return getpass.getuser().decode(locale.getdefaultlocale()[1])
TypeError: decode() argument 1 must be string, not None
Update: I am using ubuntu 12.04. I found a possible solution. add following code to manage.py. however there's a disclaimer next to it "I have no idea if this causes any negative side effects.". I am looking for a better way to fix it.
import os
os.environ.setdefault('LANG','en_US')
This is a bug in the Django code (see the django bug report).
The usual way in the ticket to fix this is to export your shell LANG environment variable.
export LANG="en_US.UTF-8"
That one works for me on a SuSE setup.
export LANG="en_US.UTF-8"
Works for me, but a way to do it by editing manage.py, django-admin creates a different directory structure than it used to and I'm moving files like settings.py, urls.py out of the subfolder.
EDIT: os.environ["LANG"]="en_US.UTF-8" (after doing import os)
I used sys.append to add the path to avoid import errors.
To reset my app, I ran this:
./manage.py reset node
It is giving me this error output:
WARNING:root:The rdbms API is not available because the MySQLdb library could not be loaded.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/home/a/mywebsites/django/seperolinux/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/a/mywebsites/django/seperolinux/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 286, in handle
app_output = self.handle_app(app, **options)
File "/home/a/mywebsites/django/seperolinux/django/core/management/commands/reset.py", line 35, in handle_app
sql_list = sql_reset(app, self.style, connection)
File "/home/a/mywebsites/django/seperolinux/django/core/management/sql.py", line 107, in sql_reset
return sql_delete(app, style, connection) + sql_all(app, style, connection)
File "/home/a/mywebsites/django/seperolinux/django/core/management/sql.py", line 66, in sql_delete
table_names = connection.introspection.get_table_list(cursor)
AttributeError: 'DatabaseIntrospection' object has no attribute 'get_table_list'
How do I reset a Model in Django-nonrel?
./manage.py reset node
executes sqlreset to create DROPT TABLE and CREATE TABLE SQL
statements for the given app.
https://docs.djangoproject.com/en/1.3/ref/django-admin/#reset-appname-appname
This does not work with the App Engine Datastore, because the Datastore is schemaless so there is no need for CREATE/DROP table commands.
If you want to delete existing model from the datastore, you can use the App Engine Development Console to delete all entities of the model (just make sure you use the correct port when accessing the Development Console) .
When I try to install ByteFlow on my Windows development machine, I got the following MySQL error, and I don't know what to do, please give me some suggestion. Thank you so much!!!
E:\byteflow-5b6d964917b5>manage.py syncdb
!!! Read about DEBUG in settings_local.py and then remove me !!!
!!! Read about DEBUG in settings_local.py and then remove me !!!
J:\Program Files\Python26\lib\site-packages\MySQLdb\converters.py:37: DeprecationWarning: the sets module is deprecated
from sets import BaseSet, Set
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table django_flatpage
Creating table actionrecord
Creating table blog_post
Traceback (most recent call last):
File "E:\byteflow-5b6d964917b5\manage.py", line 11, in <module>
execute_manager(settings)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\__init__.py", line 362, in execute_manager
utility.execute()
File "J:\Program Files\Python26\lib\site-packages\django\core\management\__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 222, in execute
output = self.handle(*args, **options)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 351, in handle
return self.handle_noargs(**options)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\commands\syncdb.py", line 78, in handle_noargs
cursor.execute(statement)
File "J:\Program Files\Python26\lib\site-packages\django\db\backends\util.py", line 19, in execute
return self.cursor.execute(sql, params)
File "J:\Program Files\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 84, in execute
return self.cursor.execute(query, args)
File "J:\Program Files\Python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "J:\Program Files\Python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
Try to change MySql default storage engine to MyISAM.
I have new to python and django I am creating poll application and in that application after creating models poll and choice using "South". I want to changer the length of question field from 200 to 300 but I am not able to achieve it even using south as well.
I have run python manage.py schemamigration polls --initial command to create migration file then I make change in poll question field that is (question = models.CharField(max_length=250)) change max_length from 200 to 250.
and the again run python manage.py schemamigration polls --auto this will generate new migration file.
after that all stuff I run python manage.py migrate polls and it shows following error :
C:\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
Running migrations for polls:
- Migrating forwards to 0003_auto__chg_field_poll_question.
> polls:0003_auto__chg_field_poll_question
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = ALTER TABLE `polls_poll` ; []
= ALTER TABLE `polls_poll` MODIFY `question` varchar(200) NOT NULL;; []
= ALTER TABLE `polls_poll` ALTER COLUMN `question` DROP DEFAULT; []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 195,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 222,
in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\south\management\commands\migrate.py", lin
e 109, in handle
ignore_ghosts = ignore_ghosts,
File "C:\Python26\lib\site-packages\south\migration\__init__.py", line 202, in
migrate_app
success = migrator.migrate_many(target, workplan, database)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 220, i
n migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, datab
ase)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 291, i
n migrate_many
result = self.migrate(migration, database)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 125, i
n migrate
result = self.run(migration)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 99, in
run
return self.run_migration(migration)
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 81, in
run_migration
migration_function()
File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 57, in
<lambda>
return (lambda: direction(orm))
File "C:\mysite\..\mysite\polls\migrations\0003_auto__chg_field_poll_question.
py", line 12, in forwards
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.C
harField')(max_length=250))
File "C:\Python26\lib\site-packages\south\db\generic.py", line 330, in alter_c
olumn
self.delete_foreign_key(table_name, name)
File "C:\Python26\lib\site-packages\south\db\generic.py", line 588, in delete_
foreign_key
constraints = list(self._constraints_affecting_columns(table_name, [column],
"FOREIGN KEY"))
File "C:\Python26\lib\site-packages\south\db\mysql.py", line 140, in _constrai
nts_affecting_columns
""", [db_name, table_name, type])
File "C:\Python26\lib\site-packages\south\db\generic.py", line 134, in execute
cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 19, in e
xecute
return self.cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 84
, in execute
return self.cursor.execute(query, args)
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 168, in execute
if not self._defer_warnings: self._warning_check()
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 82, in _warning_
check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2)
Please help me
0003 Look like :
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Poll.question'
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=250))
def backwards(self, orm):
# Changing field 'Poll.question'
db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=200))
Ansh J
Go modify the mysql table from the mysql console already!
python manage.py dbshell
alter table appname_modelname modify `question` varchar(200) NOT NULL;
To be able to answer this question with any certainty you'll need to show migrations 0002 and 0003...
However, it seems to me the resulting exception is simply a problem with MySQL (it cannot find its 'slow log') that creates a warning that is propagated to south, which trips over it.
The problem you're having is not in Django or South, it's in MySQL. MySQL is coughing up the following:
_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2)
and it's panicking the MySQLdb library, which is triggering the bailout, even though it's just a warning.
You need to find out why MySQL is so concerned about its missing slow_log file.
I suspect that you likely have general_log and slow_log frm files within
the mysql database directory, without any corresponding data files. If
this is the case then just 'rm' the general_log.frm and slow_log.frm
files from the mysql database directory, and all these errors should go
away.