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
Related
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)
I have no valuable data in my database and was unable to migrate, as you can see here:
ResetDjango postgresql database? flush does not work
I tried to reset the database using:
Delete migration files
Enter psql command prompt. Connect to database. drop schema public cascade; create schema public;
Step 2 unfortunately seemed to have removed my user role and rights so I went back to the psql command promt and recreated those.
Now I have tried to migrate again, and it still doesn't work. What might be wrong now?
vagrant#vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py makemigrations
Migrations for 'core':
0001_initial.py:
- Create model Student
vagrant#vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py migrate Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: no schema has been selected to create in
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 57, in ensure_schema
editor.create_model(self.Migration)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 284, in create_model
self.execute(sql, params or None)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: no schema has been selected to create in
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 "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 59, 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 (no schema has been selected to create in
)
Adding these two lines in settings.py at the top are important for mysql to connect:
from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField']='datetime'
I try to deploy app on Heroku but after running command 'heroku run python manage.py migrate' I get an error:
Running `python manage.py migrate` attached to terminal... up, run.5928
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 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 173, in build_graph
self.load_disk()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 103, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/joins/migrations/0004_auto_20150211_1924.py", line 7, in <module>
class Migration(migrations.Migration):
File "/app/joins/migrations/0004_auto_20150211_1924.py", line 18, in Migration
preserve_default=True,
TypeError: __init__() got an unexpected keyword argument 'preserve_default'
Do you have any suggestion?
You can try to see this :
Django 1.7.1 added support for the preserve_default param in AlterField. Therefore an upgrade of Django from version 1.7 will resolve the issue.
pip install django --upgrade
python manage.py migrate
From : Django 1.7 Migrations
.
I am trying to apply tutorial http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html.
But I didn't succeed to perform the initial database setup
Why do I get this error when I run "python manage.py syncdb --all" ?
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 230, in execute
self.validate()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 5, in <module>
class Link(CMSPlugin):
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 11, in Link
url = models.URLField(_("link"), verify_exists=False, blank=True, null=True)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 1265, in __init__
CharField.__init__(self, verbose_name, name, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 614, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'verify_exists'
The verify_exists parameter for UrlField was deprecated in the 1.3.1 security release and removed in the current Git master (1.5dev). https://docs.djangoproject.com/en/1.4/internals/deprecation/. This makes this version of django-cms incompatible with the current master. I would recommend using a stable Django release such as the latest 1.4 rather than master.
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.