InvalidBasesError when running migrate in Django - django

I'm trying to discover django-cms.
I've made a fresh project (following these steps). But when I do a django migrate, I get the following issue:
>>>python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: treebeard, menus, sekizai, cms, djangocms_admin_style
Apply all migrations: sessions, reversion, auth, admin, contenttypes, sites, djangocms_picture
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying djangocms_picture.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
if self.detect_soft_applied(migration):
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
apps = project_state.render()
File "/home/vmonteco/.Envs/django-cms/lib/python3.4/site-packages/django/db/migrations/state.py", line 75, in render
"for more" % new_unrendered_models
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'cms.PageUser'>, <ModelState: 'cms.PageUserGroup'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
Here is my INSTALLED_APPS :
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.auth',
'django.contrib.sites',
'djangocms_admin_style', # for the admin skin. must be before 'django.contrib.admin'
'django.contrib.admin',
'cms', # django CMS itself
'treebeard', # utilities for implementing a tree (replaces mptt)
'menus', # helper for model independent herarchical website navigation
'sekizai', # for JS and CSS management.
'reversion', # to versionize content
#'djangocms_file',
#'djangocms_picture',
#'djangocms_video',
#'djangocms_link',
#'djangocms_text_ckeditor', # django text plugin
)
This error occurs when I uncomment one of the last lines. Why?
How could I fix this?

I found the solution here.
You have to change MIGRATION_MODULES in your project settings, removing _django from some of the values. The linked page mentions cms and menus, but I had to remove it from djangocms_link and djangocms_text_ckeditor too.

Related

Django suddenly gives me error that Apps aren't loaded yet

I am using Django3.1. All was working fine. I pip installed a new app and tried to run makemigrations. It suddenly doesn't work anymore. I get error 'Apps are not loaded yet'. I thought it was the app. Uninstalled it. Didn't work. Deleted the virtualenv directory. Created new one and installed all apps again except the last one. It didn't work. I had installed another version of Postgres and hadn't restarted my computer since then. Restarted but didn't work. Tested by running another project to make sure it was not new Postgres issue. That worked as expected.
Commented out my url confs and installed apps in the settings.py. But still the same error.
Tried multiple SO suggestion related to this error but nothing works. Can anyone please help.
Error from console:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\checks\translation.py", line 60, in check_language_settings_consistent
get_supported_language_variant(settings.LANGUAGE_CODE)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\__init__.py", line 299, in get_supported_language_variant
return _trans.get_supported_language_variant(lang_code, strict)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 488, in get_supported_language_variant
if code in supported_lang_codes and check_for_language(code):
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 451, in check_for_language
for path in all_locale_paths()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 428, in all_locale_paths
for app_config in apps.get_app_configs():
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\apps\registry.py", line 145, in get_app_configs
self.check_apps_ready()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\apps\registry.py", line 136, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Thanks
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_name', #i hope you added app_name in settings file
or
'app_name.apps.app_nameConfig' #else try this app_name is name of your app,apps is constant key word and you will get class app_nameConfig in apps.py file
]

Issue with importing rest_framework inside django app

I am facing an issue of importing rest_framework inside my django app whenever i try to make migrations or create superuser or simply run the runserver.
I have installed the framework using this command but django still doesn't recognize it
sudo pip install djangorestframework
here's the snippet of settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'companies.apps.CompaniesConfig',
]
REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.HyperlinkedModelSerializer',
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
Output:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/core/management/__init__.py", line 364
in execute_from_command_line utility.execute()
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/tam/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/home/tam/Canopy/appdata/canopy-1.7.4.3348.rh5-x86_64/lib/python2.7/
importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named rest_framework

Import Error: No module named django - for specific project

I have installed Django(1.8.2) in my Ubuntu 16.04.
When I cloned a working project into it and run the server, I got the following error.
Traceback (most recent call last):
File "manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/lib/python2.7/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/django/apps/config.py", line 119, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Observation(s):
I'm able to start a new project and run the server of the same.
The value of INSTALLED_APPS in settings.py is:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Telecommands',
'Telemetry',
'captcha',
'django.contrib.sitemaps',
'djcelery',
'kombu.transport.django',
# 'grappelli',
# 'chronograph',
# 'registration', # Include the registration
)
What have I tried?
Installing django using pip install django==1.8.2.
Since the error was reported with reference to /usr/lib/python2.7/,
I tried:
sudo pip install --install-option="--install-purelib=/usr/lib/python2.7/site-packages/" --ignore-installed django==1.8.2
Further, when I got confused with paths
/usr/local/lib/python2.7/dist-packages,
/usr/lib/python2.7/dist-packages/
and ~/.local/lib/python2.7/dist-packages.
I installed django(1.8.2) to each of these paths one by one,
updating PYTHONPATH in parallel.
I did not get any errors while installing.
Can somebody help me out. Kindly explain the reason for the error as well.
The traceback shows you the error occurs in /usr/lib/python2.7/django/__init__.py, so manage.py has clearly found your Django installation. As an aside, it would be much better to use a virtual env instead of installing in /usr/lib/python2.7/site-packages/.
The problem appears to be that you have kombu.transport.django in your INSTALLED_APPS. The Django transport was removed from kombu in 4.0.

django 1.9: ProgrammingError: relation "users_user" does not exist

I am running into a ProgrammingError when doing migrate, I think it may be related to the use of django-allauth with a custom user. Here is what I do
1/ Create a fresh database with psql:
create database dj_example;
2/ Installed_apps contain django.contrib.sites:
DJANGO_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
)
THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
#'allauth.socialaccount', # registration
#'allauth.socialaccount.providers.twitter',
'djcelery', #Celery
)
LOCAL_APPS = (
'tucat.users', # custom users app
}
3/ site_id is set to 1
SITE_ID = 1
4/ Custom user model is overly simple:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
def __unicode__(self):
return self.username
5/ Makemigrations works fine
# python manage.py makemigrations
Migrations for 'djcelery':
0028_auto_20160601_1919.py:
- Alter field status on taskmeta
6/ Migrate returns ProgrammingError: relation "users_user" does not exist
# python manage.py migrate
Operations to perform:
Apply all migrations: auth, contenttypes, djcelery, account, admin, sessions
Running migrations:
Rendering model states... DONE
Applying account.0001_initial...Traceback (most recent call last):
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "users_user" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/antoinet/.virtualenvs/tucat/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/antoinet/.virtualenvs/tucat/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/antoinet/.virtualenvs/tucat/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/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 90, in __exit__
self.execute(sql)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/antoinet/.virtualenvs/tucat/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "users_user" does not exist
Any idea of how to resolve that problem?
You have to delete the migrations folder and then, you should do
python manage.py migrate --run-syncdb
python manage.py migrate --fake appname
Your error is caused by the order you run the migrations. Since many apps depend on the user model existing, you must run the initial migrations for your custom user app before those other apps.
If you change the default user model in an existing project, it might be easier to discard all existing migrations (and the database) and rebuild from scratch. The order to apply migrations would be:
The core django.contrib apps.
Your custom user app.
Other custom apps and third party apps.
You can use django-admin showmigrations to see which migrations exists and are planned.
FYI-
I had this problem, and to resolve it I had to comment out all references to views.py in my urls.py and url_tenants.py files. Then, I ran makemigrations and got the database tables to create, then run migrate_schemas, and later uncomment the url files. Hope this helps someone.

django-registration as an APP errors out on __init__.py

I am trying to use django-registration package on my project as an APP. All I did was
Downloaded the package from ""
Copied the "registration" folder under SOWL
In my project's URLs.py added
(r'^accounts/', include('registration.backends.default.urls')),
in my project's settings.py added "registration"
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'CATALOG',
'SOWLAPP',
'registration',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
it gives the following error -
C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL>python manage.py runserver
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
443, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 217,
in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", lin
e 105, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 194, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 183, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 160, in _fetch
app = import_module(appname)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL\registration\__init__.py", li
ne 3
<!DOCTYPE html>
^
SyntaxError: invalid syntax
C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL>
I am looking at the urls.py, __init__.py from the registration package and they all look different from the usual urls.py, __init__.py from in the regular apps under my project. Why are they different and what should I do to make it different?
SHM
It looks like something has gone wrong when you were copying the registration app . The traceback suggests that __init__.py contains html like <!DOCTYPE html>, which it definitely shouldn't.