Error when i execute syncdb - django

I am facing an error while executing python manage.py suncdb
the error is
C:\Python25\lib\site-packages\django\conf\__init__.py:75: DeprecationWarning: Th
e ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
"use STATIC_URL instead.", DeprecationWarning)
C:\Python25\lib\site-packages\django\contrib\localflavor\ca\ca_provinces.py:14:
RuntimeWarning: There have been recent changes to the CA localflavor. See the re
lease notes for details
RuntimeWarning
Creating tables ...
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
442, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 191,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 220,
in execute
output = self.handle(*args, **options)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 351,
in handle
return self.handle_noargs(**options)
File "C:\Python25\lib\site-packages\django\core\management\commands\syncdb.py"
, line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "C:\Python25\lib\site-packages\django\core\management\sql.py", line 189,
in emit_post_sync_signal
interactive=interactive, db=db)
File "C:\Python25\lib\site-packages\django\dispatch\dispatcher.py", line 172,
in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Python25\lib\site-packages\django\contrib\contenttypes\management.py"
, line 47, in update_contenttypes
content_type_display = '\n'.join([' %s | %s' % (ct.app_label, ct.model) f
or ct in content_types])
AttributeError: 'unicode' object has no attribute 'app_label'
and i tried to convert DB and all tables and fields collation to utf8_general_ci but nothing changed

The error says you've got a string instead of Model Meta options. It's not related to collation probably.
What change have you made before the error appeared?

I had this issue, I just dropped the database and re-ran syncdb and it was fine.

Related

Django 2.2 + AttributeError: 'str' object has no attribute 'decode'

We have done Django Upgrade from 1.11 to 2.2 version, we have almost completed, but there is one issue is present, when we run migrations by using the command python manage.py makemigrations
then we are getting following error.
but when we follow the below link issue is resolved.
Migrations error in django 2; AttributeError: 'str' object has no attribute 'decode'
but, I just want to know is there any other way to resolve this issue? I am feeling like there will be library to update which is causing this issue?
When we add manually as suggested in above link, its working fine, but we have docker integration to the project, then it will fail?
same issue is not happening with below django 2.2 and above 2.2.20 versions.
Error message is:
(env4) user2#SK385 pro % python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/loader.py", line 283, in check_consistent_history
applied = recorder.applied_migrations()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/django/db.py", line 65, in cursor
return DbApiTracedCursor(conn._datadog_original_cursor(), pin)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
self.init_connection_state()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 231, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/features.py", line 82, in is_sql_auto_is_null_enabled
cursor.execute('SELECT ##SQL_AUTO_IS_NULL')
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/dbapi/__init__.py", line 90, in execute
return self._trace_method(self.__wrapped__.execute, self._self_datadog_name, query, {}, query, *args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/dbapi/__init__.py", line 44, in _trace_method
return method(*args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
user2
I think you're hitting this issue because you're using PyMySQL.
The issue was fixed in ticket 30380, but wasn't backported to Django 2.2.X because Django doesn't officially support PyMySQL.
Some options are:
Upgrade to Django 3.0.X+
Switch from PyMySQL to mysqlclient
patch your version of Django 2.2 (see the fix here)

Django CMS migrate from SQLite to PostgreSQL

I'm developing a project with Django CMS 3.5. I used SQLite for development and have data in there. Now I'm trying to migrate to PostgreSQL. My steps so far:
python manage.py dumpdata --natural-primary --natural-foreign > dump.json
Switching to production settings
python manage.py migrate
TRUNCATE django_content_type CASCADE;
python manage.py loaddata dump.json
But I encounter the next error:
Traceback (most recent call last):
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in __get__
rel_obj = getattr(instance, self.cache_name)
AttributeError: 'Page' object has no attribute '_node_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 69, in handle
self.loaddata(fixture_labels)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 109, in loaddata
self.load_label(fixture_label)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 175, in load_label
obj.save(using=self.using)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/serializers/base.py", line 205, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/base.py", line 833, in save_base
update_fields=update_fields,
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/signals/page.py", line 8, in pre_save_page
instance.clear_cache(menu=True)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 963, in clear_cache
menu_pool.clear(site_id=self.node.site_id)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 184, in __get__
rel_obj = self.get_object(instance)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 159, in get_object
return qs.get(self.field.get_reverse_related_filter(instance))
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
self.model._meta.object_name
cms.models.pagemodel.DoesNotExist: Problem installing fixture '/home/webmaster/tc56/dump.json': TreeNode matching query does not exist.
This was fixed a few days ago.
Will land with django CMS 3.5.3

unable to create superuser in python Django

I have read questions in Stackoverflow and googled, but no luck.
I am trying to create a superuser in pycharm(manage.py createsuperuser
) but got below error:
"cassandra.protocol.SyntaxException: "
Not checking migrations as it is not possible to access/create the django_migrations table.
Traceback (most recent call last):
File "C:\Users\skum\PQP_Bridge\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 63, in execute
return super(Command, self).execute(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 96, in handle
default_username = get_default_username()
File "C:\Python27\lib\site-packages\django\contrib\auth\management\__init__.py", line 148, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 374, in get
num = len(clone)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 232, in __len__
self._fetch_all()
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 894, in execute_sql
raise original_exception
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:260 no viable alternative at input '.' (
...auth_user.date_joined FROM auth_user WHERE [auth_user]....)">
what am I doing wrong?
I am using Cassandra 3.0, Python Django 1.11.4, and pycharm.
We can not use: python manage.py createsuperuser using Cassandra It do not work with default django model. You need to use external library for the same. user module does not work with Cassandra by default
Please read document on data-stax or below given link. https://pypi.python.org/pypi/django-cassandra-engine/

ValidationError during Django-South migration

So, I am learning to use South and I've been running in a few issues. I did the initial app migration with the model looking like this:
class Poll(models.Model):
pass
Then added my fields...
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField()
and during the migration South complained that those fields didn't have a default, so I entered some but it didn't work... now when I try deleting them from the model and migrating back to the empty mode I get the following traceback:
mirkocrocop#Mirkos-MacBook-Pro:~/workspace/toastdriven$ python manage.py migrate polls
Running migrations for polls:
- Migrating forwards to 0007_auto__del_field_poll_question.
> polls:0003_auto__add_field_poll_question__add_field_poll_pub_date
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/__init__.py", line 213, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 235, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 310, in migrate_many
result = self.migrate(migration, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
result = self.run(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 106, in run
dry_run.run_migration(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 191, in run_migration
self._run_migration(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 178, in _run_migration
raise exceptions.FailedDryRun(migration, sys.exc_info())
south.exceptions.FailedDryRun: ! Error found during dry run of '0003_auto__add_field_poll_question__add_field_poll_pub_date'! Aborting.
Traceback (most recent call last):
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 175, in _run_migration
migration_function()
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/Users/mirkocrocop/workspace/toastdriven/polls/migrations/0003_auto__add_field_poll_question__add_field_poll_pub_date.py", line 19, in forwards
keep_default=False)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/sqlite3.py", line 31, in add_column
field.column: self._column_sql_for_create(table_name, name, field, False),
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/sqlite3.py", line 189, in _column_sql_for_create
sql = self.column_sql(table_name, name, field, with_name=False, field_prepared=True)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/generic.py", line 688, in column_sql
default = field.get_db_prep_save(default, connection=self._get_connection())
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 292, in get_db_prep_save
prepared=False)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 816, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 801, in get_prep_value
value = self.to_python(value)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 785, in to_python
raise exceptions.ValidationError(msg)
ValidationError: [u"'0' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
How could I fix this, and what is the correct way of adding these fields + doing the migration from the empty model to the field populated model? I've been going through South's docs but I don't get it... I did everything according to the documentation, but I'm not sure what should I default the DateTimeField to...
At the time you have to provide a default value, you are interacting with a python interpreter. As it is mentioned, the datetime module is available at that point in time. To provide a default for a DateTimeField in this case, just provide a datetime object:
# Use the current date and time
datetime.datetime.now()
# Or a specific date and time
datetime.datetime(2012, 10, 1, 17, 30, 0, 0)

Django South migration error

I am getting an error trying to apply a first South migration. I have tried various suggestions (like removing .pyc files in the migrations folder, converting the app as well as trying to start it afresh, other fiddles). Can anyone here suggest what I might do? Thanks
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py convert_to_south crewcal
This application is already managed by South.
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrateTraceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
In my case the AttributeError: 'module' object has no attribute 'Migration' error was simply a matter of having an extra .py file in my migrations folder.
I had an extra utilities module in my migrations directory which caused South to choke. Moving the module into a different directory (above my apps migrations directory) solved the problem for me.
Maybe a bit late, but still...
Is it possible you have any other package (folder with __init__.py) in your migration package and it interferes with the structure?
Wow. I was getting the AttributeError: 'module' object has no attribute 'Migration' error for a completely different reason than the above answers.
I had a migration file which had a bad indent:
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
As opposed to ...
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
I don't know why I had that but when I fixed that the error was gone.