syncdb not happening using south for migration - django

Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.staticfiles
> django.contrib.admin
> django.contrib.admindocs
> kaarya.account
> kaarya.project
> south
Not synced (use migrations):
- kaarya.inspector
(use ./manage.py migrate to migrate these)
Finished "C:\Documents and Settings\EC.32-SAMUEL\workspace\kaarya\kaarya\manage.py syncdb" execution.
I once installed south and tried implementing migration then also prompted as Not synced (use migrations ):
Note : Here kaarya is my project and inspector is the app i tried migrating once using south but was not successful

Did you try
python manage.py migrate
If so what was the error?

Related

Heroku created table but when I'll migrate, he says that doesn't created

I made syncdb (Python/Django application) in Heroku and he created table south_migrationhistory,
(venv-project)username#username:~/projectapp$ heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.5529
Syncing...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table south_migrationhistory
(...)
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.staticfiles
> django.contrib.admin
> south
Not synced (use migrations):
- core
- galeria
(use ./manage.py migrate to migrate these)
but when I'll migrate application he says that table wasn't created:
(venv-project)username#username:~/projectapp$ heroku run python manage.py migrate core
Running `python manage.py migrate core` attached to terminal... up, run.7542
(...monstruous log...)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: south_migrationhistory
What can be? Thanks.
EDIT:
Solved, I put in settings_local gitignore and thereby recognized the database postgres heroku.
Tested on Django 1.9
settings.py
in_heroku = False
if 'DATABASE_URL' in os.environ:
in_heroku = True
import dj_database_url
if in_heroku:
DATABASES = {'default': dj_database_url.config()}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Then run:
heroku addons:create heroku-postgresql:hobby-dev
sudo apt-get intall postgresql libpq-dev
pip install dj-database-url psycopg2
pip freeze >requirements.txt
git add .
git commit -m 'msg'
git push heroku master
heroku run python manage.py migrate
References:
There is no more syncdb, just migrate: What should I use instead of syncdb in Django 1.9?
https://devcenter.heroku.com/articles/deploying-python
https://devcenter.heroku.com/articles/heroku-postgresql
local_settings.py
import os
SITE_ROOT = os.path.dirname(__file__)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(SITE_ROOT, 'data.sqlite3'),
}
}
In your gitignore, add this:
project_name/local_settings.py
*.sqlite3

django redistributable app with south

Django apps that are meant to be redistributed don't have a manage.py (nor a settings.py since that is part of the project, not the app).
How does one run schemamigration --auto in this scenario? Do I need to have a minimal settings/manage.py as part of the app repository in order to do this? Is there a way to do this with django-admin.py?
You just need to add the app to your Installed_Apps in your settings.py
Then you can run ./manage.py schemamigration <app_name> --auto
If the app doesn't have any migrations you will want to run ./manage.py schemamigration <app_name> --initial first and then ./manage.py schemamigration <app_name> --auto from then on.
Just managed to get this working in one of my project. Here's the code that works for me:
import sys
from django.conf import settings
from django.core.management import call_command
if not settings.configured:
settings.configure(
ROOT_URLCONF='',
DEBUG=False,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db'
}
},
INSTALLED_APPS=(
'south',
'my_app',
)
)
if __name__ == "__main__":
call_command('schemamigration', 'my_app',
initial=len(sys.argv) > 1,
auto=len(sys.argv) == 0
The above script is saved as migrate.py and run with python migrate.py or python migrate.py i (the i can be anything, and it will use --initial instead of --auto if present). Obviously, you can do fancier command line option parsin, but this works for me.
EDIT: Updated the script, DATABASES key was missing. On this project, I used the same database for testing the code, so it's not an entirely arbitrary configuration.

How to delete all data for one app in Django 1.4 now that reset is gone?

How do I delete all the data in the database for on Django app? In previous version manage.py reset APPNAME did the job, but that's been deprecated.
What are we supposed to do now if we want to delete all the data from an app using the command line?
reset and sqlreset were both just wrappers around other management commands. sqlreset in particular can be duplicate by simply running:
python manage.py sqlclear myapp
python manage.py sqlall myapp
reset only served to automatically run the result of sqlreset on the database. Personally, I think removing that is a fantastic idea. Still, if you want similar functionality, you can just pipe the output to your database's shell commands.
For PostgreSQL, for example:
python manage.py sqlclear myapp | psql mydatabase
python manage.py sqlall myapp | psql mydatabase
If you want single command that should work with most database types you can pipe the drop table statements, that sqlclear generates, to dbshell
python manage.py sqlclear myapp | python manage.py dbshell
from django.contrib.contenttypes.models import ContentType
for ct in ContentType.objects.all()
ct.model_class().objects.all().delete()
Now that Django integrates migrations by default, you first need to make migrations for your app are first unapplied then deleted.
Here is the command line that works at least with Django 1.8 (replacing by the application you want to delete all associated data and:
# First, update the DB so it thinks no migrations were applied to the app
python manage.py migrate --fake <app_name> zero
# Erase all migrations in the app folder
rm -r "<app_name>/migrations/*"
# Erase the application tables
python manage.py sqlclear <app_name> | python manage.py dbshell
# Recreate the app tables, that will be empty
python manage.py makemigrations <app_name>
python manage.py migrate <app_name>
DIY
If you want to do that from the command line, create the following custom command:
from django.core.management.base import AppCommand, CommandError
from django.utils.six.moves import input
from django.db import DEFAULT_DB_ALIAS, connections
class Command(AppCommand):
help = (
'Removes ALL DATA related to the given app from the database '
'by calling model.objects.all().delete() for all app models. '
'This also removes related data in other apps via cascade.'
)
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument(
'--noinput', '--no-input',
action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind.',
)
parser.add_argument(
'--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
help='Nominates a database to reset. Defaults to the "default" database.',
)
def handle_app_config(self, app_config, **options):
app_label = app_config.label
database = options['database']
interactive = options['interactive']
db_name = connections[database].settings_dict['NAME']
confirm = (ask_confirmation(app_label, db_name)
if interactive else 'yes')
if confirm == 'yes':
for model in app_config.get_models():
model.objects.using(database).all().delete()
self.stdout.write('Reset done.\n')
else:
self.stdout.write("Reset cancelled.\n")
def ask_confirmation(app_label, db_name):
return input("""You have requested a reset of the application {app_label}.
This will IRREVERSIBLY DESTROY all data related to the app currently in
the {db_name} database, and return each table to empty state.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: """.format(**locals()))
Copy it to app/management/commands folder in any of your apps folders and run it with
./manage.py app_db_tables_reset any_installed_app_name
Ready-made package
The command is available in the django_commands package, you can install it with
pip install git+http://github.com/mrts/django-commands.git
and add it to INSTALLED_APPS to activate the command.
Tested with Django 1.9, it may or may not work with 1.8.

How to syncdb when adding a new app and south is installed?

I've got a Django app with South installed. I added an app ("guardian") in my INSTALLED_APPS. Now when I run python manage.py syncdb I get:
$ python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.admin
> south
Not synced (use migrations):
- myapp
- guardian
and trying the migration returns:
Nothing seems to have changed.
Is there any way to use the original syncdb, not the South one?
Thanks
Are you running manage.py migrate guardian?
"Nothing seems to have changed" looks like an output of running manage.py schemamigration, which wouldn't create any tables to begin with...
You can remove "south" from INSTALLED_APPS then run syncdb and finally, add "south" to INSTALLED_APPS again.

django paypal_ipn table does not exist

I am trying to implement django-paypal (dcramer's version) with IPN and although I get the notification, it is answered with a 500 error. I checked my debug log and I saw this message:
DatabaseError: (1146, "Table 'myproject.paypal_ipn' doesn't exist")
none of the tutorials I have found mentioned anything about pypal_ipn table. I also did a syncdb and a south migrate but the table is not created.
What am I doing wrong?
this is what I get with a syncdb:
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.staticfiles
> debug_toolbar
> grappelli
> filebrowser
> tinymce
> south
> avatar
> django.contrib.admin
> notification
Not synced (use migrations):
- paypal.standard.ipn
$ python manage.py schemamigration main --auto
Nothing seems to have changed.
$ python manage.py migrate main
Running migrations for main:
- Nothing to migrate.
- Loading initial data for main.
No fixtures found.
Try python manage.py migrate. That should migrate the paypal app too.
(Moved from comment to here so the question may be closed. Apparently this did the trick.)
In my case I had to migrate the app explicitly
python manage.py migrate paypal.standard.ipn
If Mike S' solution doesn't work just migrate ipn (this is what worked for me)
python manage.py migrate ipn