django south fresh install --> error: unknown command 'schemamigration' - django

short story
I run ./manage.py schemamigration junk_app --initial on a completely fresh django project right after freshly installing South ( http://south.aeracode.org/ ), and I get the following error:
Unknown command: 'schemamigration'
Type 'manage.py help' for usage.
EDIT: I have version .7 (south/init.py has version = ".07")
long story
Below is almost a literal copy/paste of what just happened:
$ sudo apt-get install python-django-south
$ django-admin.py startproject junk_proj
$ cd junk_proj
$ ./managy.py startapp junk_app
$ vim settings.py #add 'south' to INSTALLED_APPS
.
$ cat settings.py
# Django settings for junk_proj project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
import os
CWD = os.getcwd()
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = CWD+'/db' # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'vgtm!i0*(qn$8m9&0u_)#(5yh(kt8%+4dlwfum%xtt-$1ge+ld'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
ROOT_URLCONF = 'junk_proj.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'south',
'junk_app',
)
.
$ ./managy.py syncdb
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 south_migrationhistory
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): yes
Username (leave blank to use 'foo'): admin
E-mail address: admin#example.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> south
> junk_app
Not synced (use migrations):
-
(use ./manage.py migrate to migrate these)
$
$./manage.py schemamigration junk_app --initial
Unknown command 'schemamigration'
Type 'manage.py help' for usage
$

You probably haven't added 'south' into the list of INSTALLED_APPS of your settings.py file.
Here's a quote from http://south.aeracode.org/docs/installation.html#installation-configure
Now you’ve installed South system-wide, you’ll need to configure
Django to use it. Doing so is simple; just edit your settings.py and
add 'south' to the end of INSTALLED_APPS.
If Django doesn’t seem to pick this up, check that you’re not
overriding INSTALLED_APPS elsewhere, and that you can run import south
from inside ./manage.py shell with no errors.
Once South is added in, you’ll need to run ./manage.py syncdb to make
the South migration-tracking tables (South doesn’t use migrations for
its own models, for various reasons).

You are probably using some old South version, 0.6.x or even 0.5.x. If you type that "./manage.py help" you should see startmigration (iirc) on the list of available commands.

Instead of using the Ubuntu package, use easy_install or pip to install South. This will ensure you have the most recent version.

I think this problem can be very elusive. I spent considerable time and I then figured out that I was overriding INSTALLED_APPS for some testing. Doh! So this is key. Be sure to add south at the end of your INSTALLED_APPS and if you override it, check that too.

If you have your settings in a settings folder, make sure you use a . and not / in the path.
Example: ./manage.py schemamigration secretballot --initial --settings=settings.jacob

check, which settings.py file you use:
./manage.py shell
import settings
settings.__file__
you may see in manage.py, which settings file Django use by defaul:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
or you may use:
$./manage.py schemamigration junk_app --settings=settings --initial
instead of:
$./manage.py schemamigration junk_app --initial

Related

Impossible to use django-allauth when there is already an `account` app?

My Django application already has an app called account. Does it mean that it is ABSOLUTELY impossible to use django all-auth because of the name conflict? Due to the existing data, the app account cannot be renamed.
settings.py:
INSTALLED_APPS = [
...
'account',
...
# For allauth:
'django.contrib.sites',
'allauth',
'allauth.account', # Name conflict
...
If so, is there a good alternative?
2-14
Per solarissmoke's suggestion. Where should I put the new app and what is it name?
Is it something like this (Of course, it is wrong)?
my_project/account/apps.py:
import allauth.account
from django.apps import AppConfig
class AccountConfig(AppConfig):
name = 'account'
class AllAuthAccountConfig(allauth.account):
name = 'allauth.account'
label = 'allauth_account' # Change this
verbose_name = 'aullauth_account'
This is a known problem with django-allauth.
You can work around it by changing your own app to use a different app label. In your app's AppConfig:
class AccountConfig(AppConfig):
name = 'my_project.apps.account'
label = 'my_project_account' # Change this
verbose_name = 'account'
And refer to this app config in your INSTALLED_APPS, e.g.,
INSTALLED_APPS = [
...
'account.apps.AccountConfig',
...
'allauth',
'allauth.account',
...
Which should now work because the app labels are unique. Note that the only issue with this is that database tables names for your account app will have to change so as not to conflict with the allauth app - this will require some data migrations (if on an established project) or creation of fresh migrations (if on a project where you can afford to clobber the database).
You can also do this with the allauth.account app if that's easier - just create a new app config anywhere in your project, e.g.,
my_project/allauth_apps/apps.py (make sure to also create __init__.py in this new directory):
class AllAuthAccountConfig(allauth.account):
name = 'allauth.account'
label = 'allauth_account' # Change this
verbose_name = 'aullauth_account'
And then in your INSTALLED_APPS replace account with my_project.allauth_apps.apps.AllAuthAccountConfig. As above, this changes the database table names.
you need to fork the git on your own and change the label
fork the source code from https://github.com/pennersr/django-allauth/
add unique label such as allauthaccount to app in django-allauth/allauth/account/apps.py on your own forked git
commit
add following line to your requirements.txt -e git+https://github.com/andylee0213/django-allauth#egg=django_allauth
do "pip install -r requirements.txt and pip freeze > requirements.txt" and check github link is still in requirements.txt
but my suggestion is, instead of not receiving updates and going through all this pain, just use other auth libraries. There are many other libraries that does not depend on all auth. check
https://medium.com/codex/django-allauth-vs-dj-rest-auth-vs-python-social-auth-vs-drf-social-oauth2-ef7d50f92d16

nothing happens when running "python manage.py sql polls"

I am trying to get Django running on Google App Engine using Django non-rel. I am following the Django 1.5 tutorial However, when i run:
python manage.py sql polls
nothing is returned. Can anyone suggest why 'manage.py sql' is silently failing?
When I sync the database I get:
$ python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
The database is specified in settings.py as follows:
# Activate django-dbindexer for the default database
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': DATABASES['default']}
AUTOLOAD_SITECONF = 'indexes'
and I have remembered to include 'polls' in the settings.py
INSTALLED_APPS = (
# 'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'djangotoolbox',
'autoload',
'dbindexer',
'polls',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
and the models are present in polls/models.py
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
NOTE: If I change settings.py to use a local sqlite3 database, 'manage.py sql polls' behaves as described in the tutorial. Therefore, as far as I can tell, this has nothing to do with:
the /polls directory structure
the /polls/models.py file
the python path
Why do you expect it do anything? GAE is, specifically, a non-relational (NoSQL) datastore. There is quite simply no SQL to produce.
You should be aware that GAE, even with django-non-rel, is quite different from standard Django, and following the Django tutorial is only likely to confuse you.

Pycharm manage.py custom commands

I'm using PyCharm 2.7.2, which is the latest version to date.
In my settings file for a django project, I used the following lines to configure my INSTALLED_APPS setting variable.
DJANGO_APPS = (
....
)
THIRD_PARTY_APPS = (
'south',
)
LOCAL_APPS = (
'blog',
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PART_APPS + LOCAL_APPS
Now, south's features do not show up on manage.py. How do I run a custom manage.py command to get things working?
PyCharm doesn't understand concatenation for INSTALLED_APPS, there is an issue logged about it:
PY-8413 PyCharm settings.py parser should understand concatenation in INSTALLED_APPS initialization
Pycharm itself supports running south management commands. See relevant issue.
Looks like pycharm doesn't understand the structure of your project. Recheck if you configured it correctly.

Django: MySQL no such table: aidata.django_session

I'm running Django 1.4 on Windows 7 in Pycharm and I installed WAMP because I need to have my data in a MySQL table.
This is from setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'aidata',
'USER': 'root'
}
}
From installed_apps I uncommented:
'django.contrib.sessions'
Running manage.py syncdb does not create any tables ( even models) in my mysqldb.
I get the error when trying to acces /admin/
DatabaseError at /admin/
(1146, "Table 'aidata.django_session' doesn't exist")
Double check the db credentials
make sure you uncommented this line in your middleware:
MIDDLEWARE_CLASSES = (
....
'django.contrib.sessions.middleware.SessionMiddleware',
)
then try to python manage.py syncdb.
if you are still having issues post any output
EDIT -- NEXT CHECK:
do you have a "django_content_type" table?
if so, does that table have a "session" record?
if so, delete the session record and try to python manage.py syncdb
EDIT -- STEP 3:
now i'm guessing, post up your settings file so i can make meaningful troubleshooting attempts
Stop your server if you have one running
go into your file browser and delete the settings.pyc file
try to python manage.py syncdb
my thought is that a pyc file with the sqlLite info may be cached and not regenerating
EDIT -- STEP 4:
everything in your settings.py look ok to me. try something for me? create a new django project, don't enable the admin or add in your apps i just want to know if from scratch everything in your django install seems to be working
django-admin.py startproject testsite
do the database configuration/setup
python manage.py syncdb
let me know if the models create properly
I was running into the same problem and for me (running django 1.7 development trunk of mid-sept.2013) it helped to
remove all south migrations ([app]/migration)-directories
remove south from INSTALLED_APPS in settings.py
That might be due to the shift towards the integrated migration system in django v1.7, but I'm speculating here.

Why "no such table: django_session" when trying to use admin?

I am pretty sure that database has been created and I have executed python manage.py syncdb properly but still i encounter this error when trying to access http://127.0.0.1:8000/admin/. Here are some details.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Exception Type: DatabaseError at /admin/
Exception Value: no such table: django_session
path to sqlite is usually the problem.
'NAME': 'c:/path/to/sqlite.db'
Make migrations will solve the problem.
Run below commands:
python ./manage.py migrate
python ./manage.py makemigrations
Try this
from os.path import dirname, abspath
ROOT = dirname(abspath(__file__)).replace('\\', '/') + '/'
print "self.__name__: " + __name__
print "self.__file__: " + __file__
print "ROOT: " + ROOT
import django
print "django.__path__: "
print (django.__path__)
# Contact for error messages etc. - dont forget the ',' after the first entry
ADMINS = (('dev', 'dev#example.com'),)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ROOT + 'project.db',
'USER': '', 'PASSWORD': '',
'HOST': '', 'PORT': '',
}
}
and check if you need + '/' + before the database name for your operating system.
SESSION_ENGINE it's using django.contrib.sessions.backends.db by default and that's make you need to :
put django.contrib.sessions in INSTALLED_APPS list variable in settings.py
you must migrate your database
if you don't want to do that, just put SESSION_ENGINE to django.contrib.sessions.backends.cache in your settings.py.
so, in your settings.py like this :
...
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
...
by the way, as in the documentation say :
'..the simple cache is faster because it disregards persistence.'
you can cek in this link
If you have added/updated table in any models.py file, you might need to migrate the db before running the server.
Run below commands before running 'python manage.py runserver':
python manage.py migrate
python manage.py makemigrations
That happens when you run the server without a database created or the session table inside of it (in case you recently add the admin app to your INSTALLED_APPS). In order to create the database or the table run this command.
python manage.py migrate
In older versions of django is this command
python manage.py syncdb
It prompted you to that error page because your Database wasn't even created, which lead to the absence of the mandatory tables to access the admin page.
Run the following two commands :
python3 manage.py migrate
python3 manage.py makemigrations
Running the first command actually creates your database which holds the necessary starter tables. I had the same problem and this solved 100% for me.
Solution source : #satya 's answer
Executing in the below order works fine:
First
python manage.py migrate
Then
python manage.py runserver.
Since we are applying all migrations before running the server.