0

Hello I tried remove models, migration files and find something on stack but i didn't find anything about it.

Can you help me with that error? I'm using Django(1.8.8) on virtualenv

Error from console:

Operations to perform:
    Apply all migrations: core
Running migrations:
Rendering model states... DONE
Applying core.0024_auto_20160120_1340... OK
Applying core.0025_auto_20160120_1348...Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.2\helpers\pycharm\django_manage.py", line 41, in <module>
    run_module(manage_file, None, '__main__', True)
File "C:\Program Files (x86)\Python35-32\Lib\runpy.py", line 182, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Program Files (x86)\Python35-32\Lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
File "C:\Program Files (x86)\Python35-32\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
File "C:/Users/Bartek/PycharmProjects/CRM\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
    utility.execute()
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\core\management\__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\core\management\base.py", line 445, in execute
    output = self.handle(*args, **options)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\core\management\commands\migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\migrations\executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\migrations\executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\migrations\migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\migrations\operations\fields.py", line 62, in database_forwards
    field,
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\backends\sqlite3\schema.py", line 179, in add_field
    self._remake_table(model, create_fields=[field])
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\backends\sqlite3\schema.py", line 77, in _remake_table
    self.effective_default(field)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\backends\base\schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\models\fields\__init__.py", line 710, in get_db_prep_save
    prepared=False)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\models\fields\__init__.py", line 1482, in get_db_prep_value
    value = self.get_prep_value(value)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\models\fields\__init__.py", line 1461, in get_prep_value
    value = super(DateTimeField, self).get_prep_value(value)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\models\fields\__init__.py", line 1317, in get_prep_value
    return self.to_python(value)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\db\models\fields\__init__.py", line 1420, in to_python
    parsed = parse_datetime(value)
File "C:\Users\Bartek\dJangoEnvironment\lib\site-packages\django\utils\dateparse.py", line 93, in parse_datetime
    match = datetime_re.match(value)
TypeError: expected string or bytes-like object

0025_auto_20160120_1348.py

# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.db import migrations, models

import datetime


class Migration(migrations.Migration):

    dependencies = [
            ('core', '0024_auto_20160120_1340'),
    ]

    operations = [
            migrations.RemoveField(
                    model_name='clienthistory',
                    name='created_date',
            ),
            migrations.RemoveField(
                    model_name='clienthistory',
                    name='last_modified',
            ),
            migrations.AddField(
                    model_name='clienthistory',
                    name='content_x',
                    field=models.TextField(blank=True, null=True),
            ),
            migrations.AddField(
                    model_name='clienthistory',
                    name='log_date',
                    field=models.DateTimeField(auto_now_add=True,default=2),
                    preserve_default=False,
            ),
            migrations.AlterField(
                    model_name='order',
                    name='created',
                    field=models.DateTimeField(editable=False, default=datetime.datetime(2016, 1, 20, 13, 46, 44, 899932), help_text='Order created data'),
            ),
    ]

I'm using Git so i rollback but i still have this error.

2
  • How are you setting the "match" field? Commented Jan 20, 2016 at 13:43
  • 1
    could you post your core.0025_auto_20160120_1348 migration file? Commented Jan 20, 2016 at 13:46

1 Answer 1

1

Your log date field currently has a default of an integer assigned to it, this should be a date.

       migrations.AddField(
                model_name='clienthistory',
                name='log_date',
                field=models.DateTimeField(auto_now_add=True,default=2),  # Change to a date
                preserve_default=False,
        ),

It should also be possible just to remove the default since auto_now_add does that already

Sign up to request clarification or add additional context in comments.

2 Comments

(To prevent further migration issues this may need to be applied inside of the model too)
Thanks for help. It's weird because i didn't use a default attribute in this field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.