South 0.8.3 upgrade causes DeserializationError - django

I have a Django 1.5.5 project that uses South 0.8.2. Everything works great -- including migration using South. When I attempt to upgrade this project to South 0.8.3, I get the following error when I run python manage.py migrate:
(VBEZ)vagrant#vagrant-ubuntu-precise-64:/vagrant$ python manage.py migrate
Running migrations for django_mailbox:
- Nothing to migrate.
- Loading initial data for django_mailbox.
Installed 3 object(s) from 1 fixture(s)
Running migrations for djcelery:
- Nothing to migrate.
- Loading initial data for djcelery.
DeserializationError: Problem installing fixture 'initial_data.json': Invalid model identifier: 'sites.site'
What has happened?
Here is my initial_data.json file:
[
{
"pk": 1,
"model": "sites.site",
"fields": {
"domain": "0.0.0.0:5000",
"name": "Project (Development)"
}
},
{
"pk": 2,
"model": "sites.site",
"fields": {
"domain": "project-staging.example.com",
"name": "Project (Staging)"
}
},
{
"pk": 3,
"model": "sites.site",
"fields": {
"domain": "project.example.com",
"name": "Project"
}
}
]
Here is what a successful migration using South 0.8.2 looks like:
Running migrations for django_mailbox:
- Nothing to migrate.
- Loading initial data for django_mailbox.
Installed 3 object(s) from 1 fixture(s)
Running migrations for djcelery:
- Nothing to migrate.
- Loading initial data for djcelery.
Installed 3 object(s) from 1 fixture(s)
Running migrations for taggit:
- Nothing to migrate.
- Loading initial data for taggit.
Installed 3 object(s) from 1 fixture(s)
Running migrations for eee_core:
- Nothing to migrate.
- Loading initial data for eee_core.
Installed 3 object(s) from 1 fixture(s)
Running migrations for core:
- Nothing to migrate.
- Loading initial data for core.
Installed 3 object(s) from 1 fixture(s)
Things I have looked at/tried:
django-contrib-sites is in my `INSTALLED_APPS'
Migration works fine if the initial_data.json file is removed.
If I run migrations individually, they run fine. Example python manage.py migrate myapp.
I have submitted a ticket: http://south.aeracode.org/ticket/1324
Thanks.

Looks like this a known bug in South 0.8.3: http://south.aeracode.org/ticket/1320. Fix is expected in a week or so.
Update: South 0.8.4 fixes this bug.

Related

Why django migrate command don't insert to django_migrations table

There was a change in the DB and the Model was modified. After running Makemigrations, I ran migrate.
The DB has been changed normally, but the history is not added to the django_migrations Table.
Because of this problem, a warning to continue to migrate appears even after migrating. And when I try to migrate again, the history is not added to the django_migrations table, so I try to change the DB as before, and this is of course an error.
This is migrations file.
class Migration(migrations.Migration):
dependencies = [
('common_py', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='customer_company',
name='del_date',
field=models.DateTimeField(default=None, null=True, verbose_name='삭제일'),
),
]
Run command "python manage.py migrate"
Result
(venv) PS D:\Projects\AFF\AFF> python manage.py migrate
Operations to perform:
Apply all migrations: auth, common_py, contenttypes, sessions
Running migrations:
Applying common_py.0002_customer_company_del_date... OK
Change Table Success
But didn't add history to "django_migrations" Table
Have you any idea? I Couldn't find any information about this. Thank you.
I turned off autocommit of mariadb. To use transaction in my Django program.
This is the reason of problem. I guess that the "python manage.py migration" command is not using transaction commit.
Solution.(Os windows)
open mariadb config file.
C:\Program Files\MariaDB 10.5\data\my.ini
Then add(or change) this line in
[mysqld]
autocommit=1
Restart pc or mariadb.
Complete.

ImportError at /admin/ No module named polls_ChoiceField.urls

Django 1.6.2
MacOSX 10.9.2
Python 2.7
I recently deleted a Django App "polls_ChoiceField" which was sitting inside another app "polls" as I was only using it to test a few things. However since i deleted it then the app it was sitting in no longer works.
I deleted the file through the pyDev package explorer. When I synced the Database it gave my the option of deleting the stale content, I selected yes.
Can anyone tell me what I have to do to get the original "polls" all running again?
Relevant Terminal output
localhost:src brendan$ python manage.py syncdb
Creating tables ...
The following content types are stale and need to be deleted:
polls | choice_choicefield
polls | poll_choicefield
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
I then synced the DB
localhost:src brendan$ python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
And I am able to run the server
localhost:src brendan$ python manage.py runserver
Validating models...
0 errors found
When i try to revisit the app in my browser i get
ImportError at /polls/
No module named polls_ChoiceField.urls
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.6.2
Exception Type: ImportError
Exception Value:
No module named polls_ChoiceField.urls
Exception Location: /Library/Python/2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
Python Path:
['/Users/brendan/Dropbox/workspace/bias_experiment/src',
'/Library/Python/2.7/site-packages/distribute-0.7.3-py2.7.egg',
'/Library/Python/2.7/site-packages/setuptools-2.2-py2.7.egg',
'/Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg',
'/Library/Python/2.7/site-packages/yolk-0.4.3-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenv-1.11.4-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenvwrapper-4.2-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Mon, 28 Apr 2014 16:26:46 +0100
Thanks
EDIT:
My urls.py with the bad line of code (the middle url)
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^polls_ChoiceField/', include('polls_ChoiceField.urls', namespace="polls_ChoiceField")),
url(r'^admin/', include(admin.site.urls)),
)
Thanks again.
Check your project-level urls.py, looks like it still tries to use urls from the deleted app.

How to properly add fields to models with South?

I have a django app called Locations and in its models.py there are 2 models:
class City(models.Model):
...
class Country(models.Model):
...
I did python manage.py schemamigration Locations --initial and then python manage.py migrate Locations. Everything worked fine.
Then I added 2 fields to City and did python manage.py schemamigration Locations --auto and it said:
Deleted field cover_image on Locations.Country
Added field lng on Locations.City
Added field ltd on Locations.City
Created 0003_auto__del_field_country_cover_image__add_field_city_lng__add_field_cit.py. You can now apply this migration with: ./manage.py migrate Locations
Then when I did python manage.py migrate Locations, I got:
Running migrations for Locations:
- Migrating forwards to 0003_auto__del_field_country_cover_image__add_field_city_lng__add_field_cit.
> Locations:0001_initial
FATAL ERROR - The following SQL query failed: CREATE TABLE "Locations_country" ("id" serial NOT NULL PRIMARY KEY, "name" varchar(100) NOT NULL UNIQUE, "slug" varchar(50) NOT NULL, "image" varchar(100) NOT NULL, "flag" varchar(100) NOT NULL)
The error was: relation "Locations_country" already exists
Error in migration: Locations:0001_initial
DatabaseError: relation "Locations_country" already exists
I always keep getting this error. Am I doing something wrong?
Then I did python manage.py migrate Locations 0003 --fake and this was the output:
- Soft matched migration 0003 to 0003_auto__del_field_country_cover_image__add_field_city_lng__add_field_cit.
Running migrations for Locations:
- Migrating forwards to 0003_auto__del_field_country_cover_image__add_field_city_lng__add_field_cit.
> Locations:0001_initial
(faked)
> Locations:0002_auto__add_field_city_lng__add_field_city_ltd
(faked)
> Locations:0002_auto__add_location__add_field_country_cover_image
(faked)
> Locations:0003_auto__del_field_country_cover_image__add_field_city_lng__add_field_cit
(faked)
Now when I do python manage.py migrate Locations it says:
Running migrations for Locations:
- Nothing to migrate.
- Loading initial data for Locations.
Installed 0 object(s) from 0 fixture(s)
And those 2 fields have not been added. Whats going on? Whats the correct way to add/delete fields?
I have read the basic South documentation, please point to me if I have missed out something.
Thanks.
Delete 0002 and 0003 migrations files. And then roll back to 0001 by doing:
python manage.py migrate Locations 0001 --fake --delete-ghost-migrations
After that run schemamigration and migrate normally.
(During discussion with OP it was first cleared that 0002 and 0003 was never reflected to database, so it is no harm to delete those migration files from disk)

Why is south migrate failing?

I have a blank MySQL database that I've just created. south is in my INSTALLED_APPS.
I run:
$ ./manage.py syncdb
...
Creating table some_app_table
You just installed Django's auth system, which means you don't have any superusers defined.
...
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.auth
> django.contrib.contenttypes
...
Not synced (use migrations):
- myapp
...
$ ./manage.py schemamigration myapp --initial
+ Added model myapp.Model
...
Created 0003_initial.py. You can now apply this migration with: ./manage.py migrate myapp
$ ./manage.py migrate myapp
Running migrations for myapp:
- Migrating forwards to 0003_initial.
> skan:0001_initial
> skan:0002_initial
FATAL ERROR - The following SQL query failed: CREATE TABLE `myapp_model` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `user_id` integer NULL, `name` varchar(200) NOT NULL);
The error was: (1050, "Table 'myapp_model' already exists")
What's going on? Why won't South initialise correctly?
You already have some migrations defined: initial is (as expected) only needed for the initial migration.
Your syncdb output says:
Not synced (use migrations):
- myapp
Which indicates that south is working as expected. But, then you do:
$ ./manage.py schemamigration myapp --initial
+ Added model myapp.Model
...
Created 0003_initial.py. You can now apply this migration with: ./manage.py migrate myapp
Notice the 0003-prefix: this (most likely) indicates that there are already migrations defined. This is confirmed by the output of your next command:
$ ./manage.py migrate myapp
Running migrations for myapp:
- Migrating forwards to 0003_initial.
> skan:0001_initial
> skan:0002_initial
<snip>
In other words, you already have a couple of initial migrations, of which at least one will create that table. Your #3 migration tries this again, but fails, because the table of course exists by now.
What you need to do is only use initial on the creation of your Django app. As soon as the migrations folder contains a file called 0001_initial.py, you don't need any initial migrations anymore. If you change your table from this point on, call it with auto, and then migrate:
./manage.py schemamigration myapp --auto
./manage.py migrate myapp

How to use fixtures in django?

I've a very simple app and I've created a fixture. A folder named as fixtures and a file named as initial_data.json. Following is the code I've in my initial_data.json file:
[
{
"model": "myapp.model_in_lower_case",
"pk": 1,
"fields": {
"title": "my Title",
"description": "Description goes here..."
}
}
]
But when I run the syncdb command, it says zero fixtures found and the data is not being saved. What's missing?
Make sure you are using manage.py /dumpdata to export the fixture.
save the fixuture under your app fixtures directory not your project directory.
name it initial_data.json and it should work for you.
when the json file does not fit to your database or is invalid, manage.py will throw an exception. I am positive that currently you didnt put the json file in the right place.