rh-lab-q/conflab

cannot migrate model (please add "submissions_opened" to conference)

Closed this issue · 3 comments

I was trying to change model. So I have added new bool into Conference class in models.py and called makemigrations and syncdb. In the end it destroyed my db.

I was working with existing installtaion

python3 ./manage.py syncdb

I have updated the file /wsgi/openshift/confla/models.py like this:

class Conference(models.Model):
    submissions_opened = models.BooleanField(default=False)

Then I was trying to update database.

python3 ./manage.py makemigrations confla
python3 ./manage.py syncdb

The result was following

$ python3 ../manage.py makemigrations confla
Migrations for 'confla':
  0001_initial.py:
    - Create model ConflaUser
    - Create model Conference
    - Create model EmailAdress
    - Create model Event
    - Create model EventTag
    - Create model EventType
    - Create model HasRoom
    - Create model Page
    - Create model Paper
    - Create model Photo
    - Create model Room
    - Create model Timeslot
    - Create model VolunteerBlock
    - Create model Volunteer
    - Add field reviewer to paper
    - Add field user to paper
    - Add field room to hasroom
    - Add field e_type_id to event
    - Add field prim_tag to event
    - Add field speaker to event
    - Add field tags to event
    - Add field user to emailadress
    - Add field rooms to conference
    - Add field groups to conflauser
    - Add field schedule to conflauser
    - Add field user_permissions to conflauser
Traceback (most recent call last):
  File "../manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.4/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.4/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle
    self.write_migration_files(changes)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 171, in write_migration_files
    migration_string = writer.as_string()
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 165, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 123, in serialize
    _write(arg_name, arg_value)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 75, in _write
    arg_string, arg_imports = MigrationWriter.serialize(item)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 302, in serialize
    item_string, item_imports = cls.serialize(item)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 376, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 267, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/writer.py", line 434, in serialize
    % (value.__name__, module_name, get_docs_version()))
ValueError: Could not find function wrapper in confla.utils.
Please note that due to Python 2 limitations, you cannot serialize unbound method functions (e.g. a method declared and used in the same class body). Please move the function into the main module body to use migrations.
For more information, see https://docs.djangoproject.com/en/1.8/topics/migrations/#serializing-values

Can you please look how can I add new column into model without loosing of all data.

I've been having problems with making Django's migrate mechanism to work a few times already however not once have I managed to solve them. Altough my issues were mostly that Django wouldn't even recognize the changes I made to the models so I'll try and have a look at the issue you're having.

Regarding the change to the model - I think it would be better to add a time frame using two date (or datetime) fields instead of a boolean.

The Boolean variable was mainly demonstrating the issue with migration. I agree that feature should be limited by range of dates.

Managed to fix the issue while adding two date fields as a range of dates for CFP. However, I only got the migration working locally, not on openshift, as it would (probably) require dropping all the tables.