0

您好,我尝试删除模型、迁移文件并在堆栈上找到一些东西,但我没有找到任何关于它的东西。

你能帮我解决这个错误吗?我在 virtualenv 上使用 Django(1.8.8)

来自控制台的错误:

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'),
            ),
    ]

我正在使用 Git,所以我回滚,但我仍然有这个错误。

4

1 回答 1

1

您的日志日期字段当前具有分配给它的默认整数,这应该是一个日期。

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

也应该可以只删除默认值,因为auto_now_add已经这样做了

于 2016-01-20T13:56:07.920 回答