Table of Contents
Django-shop
Working dir:
/home/dang/data/workspace/75djangoshop/maxoshop_project
Trying to combine django-shop with 2 scoops tutorial.
Dev env preparation
Errors
sites
File "/mnt/extdata/workspace/75_django_shop/djangoshop_env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
Solution:
- delete all .pyc:
find . -name "*.pyc" -exec rm -- {} +
* Disable other apps:
Disable all external apps in your INSTALLED_APPS, except your own apps, like so:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'main', # This is my own app.
# 'compressor',
# 'ckeditor',
# 'imagekit',
# 'debug_toolbar',
# 'rest_framework',
# 'allauth',
# 'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.google',
# 'allauth.socialaccount.providers.facebook',
)
Run
python manage.py makemigrations
python manage.py migrate
Then, uncomment all the other apps, then repeat makemigrations and migrate above.
That works all the time for me
http://stackoverflow.com/questions/17891490/django-databaseerror-relation-django-site
- disable debug-toolbar then makemigrations, migrate then enable and rerun all migrations.
Make migrations / migrantion
- disable debug-toolbar python manage.py makemigrations sites python manage.py migrate sites
If we do migration new there will be error with the authxxx: Creating table maxoshopsmartphone
Running deferred SQL... ... django.db.utils.ProgrammingError: relation "auth_user" does not exist
maxoshop is using auth_user and has error. Migrate maxhoshop first:
python manage.py makemigrations maxoshop
New migrate everything:
python manage.py migrate
Import django-shop example to project
https://django-shop.readthedocs.org/en/latest/tutorial/intro.html
Copy django-shop example
cp -rp $example/myshop /home/dang/data/workspace/75_django_shop/maxoshop_project/maxoshop_project/
Merge myshop.settings with maxoshop settings.
Django app registration: myshop.apps
ImportError: No module named myshop.apps
Problem is we place myshop under $pjsroot/maxoshopproject. Some paths need to be fixed.
Fix myshop/init.py
default_app_config = 'maxoshop_project.myshop.apps.MyShopConfig'
Fix myshop/apps.py:
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class ArticlesConfig(AppConfig):
name = 'maxoshop_project.myshop' <---------- this is it
verbose_name = _(u'Ma Shop')
Further paths fix for import are required.
from myshop.models.properties import Manufacturer, ProductPage, ProductImage ImportError: No module named myshop.models.properties
Change to
from maxoshop_project.myshop.models.properties import Manufacturer, ProductPage, ProductImage #or from ...models.properties import Manufacturer, ProductPage, ProductImage
Note: we remove myshop and navigate from this module (file)
Data base
Migration
What is working?
python manage.py migrate --fake myshop 0002 python manage.py migrate --fake-initial myshop python manage.py migrate myshop
Finally got it to work, although I don't know why and I hope it will work in the future.
After doing numerous trials and going through Django's dev site (link).
Here are the steps (for whoever runs into this problem):
Empty the django_migrations table: delete from django_migrations;
For every app, delete its migrations folder: rm -rf <app>/migrations/
Reset the migrations for the "built-in" apps: python manage.py migrate --fake
For each app run: python manage.py makemigrations <app>. Take care of dependencies (models with ForeignKey's should run after their parent model).
Finally: python manage.py migrate --fake-initial
After that I ran the last command without the --fake-initial flag, just to make sure.
Now everything works and I can use the migrations system normally.
I'm sure I'm not the only one who encounters this issue. It must be documented better and even simplified.
-----------------------------
I'm getting RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually. at the final step for Django 1.8.3 though. Do you know why? – eric Sep 21 '15 at 3:45
upvote
flag
@eric try running python manage.py migrate contenttypes before the final step. – azalea Oct 14 '15 at 19:33