One wrong migration / migrations files in general
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Widelands Website |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I just found one wrong migration related to wlmaps, but it's not Critical.
First a few words about the migration files found in each app under the folder 'migrations':
Django provides a functionality to manage database related changes, like changing length of fields, adding fields to models (do you remember adding the 'hint' field to wlmaps?), or changing field parameters. This works only if a folder 'migrations' (with __init__.py) exists.
The state before the merge of the django1_8 was that we hadn't such a folder for our own apps. F.e in case of the 'hint' field of wlmaps, we had to modify the related table in the database directly, and had to be sure that the appropriate model of wlmaps reflect this changes. With the migrations folder the work were much easier: Modify the Django model, ran './manage.py makemigrations' and './manage.py migrate'. Django then will create another file in the migration folder with the needed command and apply the changes to the database table for us. Much convenient. Nevertheless there are some things to pay attention on. but those are specific to some type of fields.
The wrong migration file and why it's not critical:
The wrong file wlmaps/
('file', models.
This is totally wrong on the server... but the good news: Because of running './manage.py migrate --fake-initial' the initial files are not processed in real (applied to the database tables). They are only marked as applied and the old table schema is not affected.
Nevertheless this statement is wrong if someone else want to set up the website locally and ran './manage.py migrate'. If he/she wants testing uploading maps this will fail...
The reason why this was happened:
By investigating this failure i found that the underlying code was not the code Django expects: The 'file' field in wlmaps/models.py defines the option 'upload_to' with the whole path of MEDIA_ROOT + '/wlmaps/maps/'. This results in huge strings for the file field. I have looked into the table and found for example
"/var/www/
which is 98 chars. The field is defined with a length of 100 chars...
The solution is now to give Django what it expects: Only the additional path to MEDIA_ROOT, in this case: 'wlmaps/maps' (without the preceding and leading slashes). The value of the setting MEDIA_ROOT is applied by Django automatically. I've looked into the other models where file upload is possible and there all is fine. So it's only wlmaps which is problematic.
Next week i want to provide a branch with the needed changes to fix this.
Of course i had to take look at all the migrations files, but unfortunately i didn't. I am sorry about that...
Related branches
- SirVer: Approve
-
Diff: 29 lines (+4/-4)2 files modifiedwlmaps/migrations/0001_initial.py (+2/-2)
wlmaps/models.py (+2/-2)
- SirVer: Approve
-
Diff: 116 lines (+31/-6)4 files modified.bzrignore (+1/-0)
wlmaps/forms.py (+22/-4)
wlmaps/migrations/0001_initial.py (+1/-1)
wlmaps/models.py (+7/-1)
tags: | added: cleanups |
Changed in widelands-website: | |
status: | New → Fix Released |
This kind of thing just happens when you do huge changes - and since it worked, nobody noticed the bug for a while ;)