migrating from django-cms beta3 to 2.1.3 (stable) - python

Hey guys,
Im trying to migrate django-cms from version 2.1.0 beta3 to 2.1.3 (stable), i have read many posts that recommend South for this, unfortunately i have never done anything with south, and i didn't have it installed when creating my projects, so i have followed many solutions that include running:
python manage.py migrate --fake
on the old version and then installing the new version and run:
python manage.py migrate
however this does not work, because django throws the following error:
no such column: cms_page.limit_visibility_in_menu
so i was wondering if anyone has another solution they would like to share.
btw im using python 2.7 and Django 1.2.1

I use this sequence when db changes and we need to do schemamigration using South:
./manage.py schemamigration your_app_name --auto
Note, than database should fit your models, otherwise you'll get errors.
Then, after you get success message and invitation to migration, you do:
./manage.py migrate
That's it. Backup you database before, so you can rewind. Then you just will need to restore your dumped database and delete failed migration file from migrations directory.

Related

Create Django app with no User model - 3.1.3 wants to migrate auth_user?

I've got a Django application which has been happily humming along now for quite some time (2 years or so).
It's on 3.0.10 currently - when I tried to upgrade to 3.1.3, it says there was a migration for the auth application. No worries! Never been an issue before...
I ran python manage.py migrate and got the following error:
"Cannot find the object "auth_user" because it does not exist or you do not have permissions."
Which, I suppose would be true because we do not have a User model at all in this application. There is no auth_user table, that is correct. In other apps we have an AbstractUser that routes to a table named: org_user - but again:
this particular app (and project) do not have any User model associated with them
Obviously this (apparently, now) leads to some issues.
Any thoughts on how to get around this? I thought about removing auth from installed apps and tried that but it led to more issues when trying to runserver.
You can fake a migration using --fake option:
python manage.py migrate --fake auth
python manage.py migrate
But I suspect the error you get could be symptomatic of a project design issue, such as not setting properly settings.AUTH_USER_MODEL
Solution 1 :- Run these commands :-
python manage.py migrate auth
python manage.py migrate
Solution 2 :- Try to copy your Project in another folder and then run migrations.

What to do with unapplied migrations in Django?

Currently I have converted my python 2 project into python 3 project & earlier I was using Django version 1.9.13 & now I have updated it to 2.2.6.
Now I am able to run my project in latest version of python and django but when I run my project in cmd I have found that It showing message like You have 253 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s)... so I have checked my migrations folder and able to find all migrations files there.
Any idea why I am getting such kind of message here & if it is bug then what should I do to get rid of such problem ?
Thanks.
You need to migrate those migrations to your database. This means you have changes in your model classes but they are not applied to the database you are using. To migrate to the database: in CMD
python manage.py makemigrations
python manage.py migrate
In both cases, make sure you are inside your virtualenv (if you have one) and using the right python. For instance, in most cases if you have multiple pythons installed (2 and 3); you might have to use 'python3' in the above commands.

Missing DB table for django-background-tasks

I'd like to regularly run a backend task in my Django app and found django-background-tasks (https://pypi.python.org/pypi/django-background-tasks).
Following the page, I
pip installed the package
added it to INSTALLED_APPS
created a test method annotated with #background(schedule=5)
However, once I call the method, I get "django.db.utils.OperationalError: no such table: background_task"
Running python manage.py migrate only tells me "No migrations to apply" (the DB has tables for other registered Django apps).
Is the django-background-tasks package incomplete?
How do I create the DB objects for it?
As Moses and Ravi suggested, python manage.py makemigrations background_task needs to be ran first so that python manage.py migrate can create the table.

Django: OperationalError at /admin/

So I ran my program based on from here and It worked without any error. I go to to /admin. I login. So far everything is good. Then when it loads I get this:
I checked the traceback (which is really long) and none of includes my code. It doesn't tell me what part of the code this error is occurring in so I don't know how to approach this. Please explain what this is, why this is happening, and how I can fix it.
If you need any part of my code, just ask in comments because I don't know where this is happening.
You need to run migrate command in-order to force django to create auth tables.
python manage.py migrate
Then for any change you made on models, don't forget to run these two commands.
python manage.py makemigrations
python manage.py migrate
Use pip install django==2.1.5
If the problem persists,
Use python manage.py migrate --run-syncdb
by default, the auth table is not created in the database
so first we need to create the table and reload the page
to achieve the same
make the migrations by typing the following command
1. python3 manage.py makemigrations
2. python3 manage.py migrate
Till the time they don't debug this issue with Django and Sqlite3 use the older versions of Django
You may consider using version 1.10.5(using command pip install --upgrade django==1.10.5)
yes, that was fault of django version ,when i installed django==2.1.5 that problem was solved.
Install latest django version
$ pip3 install django==2.2.8
$ python3 manage.py makemigrations
$ python manage.py migrate
then reload page in browser
this is the problem with migration just type the following command:-
python manage.py migrate
If you still get error after you lunched
python manage.py migrate
and for every change you made on models
python manage.py makemigrations
python manage.py migrate
Then check if you have Django version older than 2.1.5, because this latter version fixes a bug returning "OperationalError>no such table" when adding an object to your database as superuser.
So try to
pip install Django==2.1.5
However, you will have to re-write your project anew.
user permission
Hi
In Django Administration :check if the user has the right permission, it should work
use these commands
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver

What should I use instead of syncdb in Django 1.9?

Take a look at this:
$ pypy ./manage.py syncdb
/usr/lib64/pypy-2.4.0/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
(cut)
I ran a quick google search, but could not find the answer - what should I be using instead of syncdb?
syncdb is deprecated because of the migration system, introduced with django 1.7.
Now you can track your changes using makemigrations. This transforms your model changes into python code to make them deployable to another databases. When you have further modifications you need applied to the database, you can use data migrations.
After you created the migrations you have to apply them: migrate.
So instead of using syncdb you should use makemigrations and then migrate.
Workflow on development after you changed something in your models:
./manage.py makemigrations
./manage.py migrate
And on your production system:
./manage.py migrate
Bonus: you do not need to run migrate for each change. If you have multiple changes not applied yet django will run them in the correct order for you.
You should definitely use migration system. Which lets you track changes in your models.py, and create migrations for the database. The migration system uses the commands makemigrations to create migrations and migrate to migrate the database.
If for whatever reason you need to create a database the same way syncdb did it there is command flag that causes migrate to work the same way. You should only do this if you REALLY need it and you know what you are doing. For example to create an empty database on for a continuous integration system of your choice.
python manage.py migrate auth
# performs migrations for auth and contenttypes contrib apps
python manage.py migrate --run-syncdb
# creates the rest of the database
Tested on Django 1.9.1.
You should use the makemigrations and migrate commands that were introduced in django 1.7
https://docs.djangoproject.com/en/1.7/topics/migrations/
syncdb has some problem with db migration. so, after django 1.7 makemigrations and migrate have been introduced.
Now in django 1.9 syncdb has been deprecated.
try
1. python manage.py makemigrations which detects changes in db and creates one .py file as inside migrations folder
2. python manage.py migrate will apply the migrations to the database

Categories

Resources