2016-01-20 215 views
0

你好,我嘗試刪除模型,遷移文件,並找到堆棧上的東西,但我沒有找到任何關於它。manage.py遷移 - 錯誤

你能幫我解決這個錯誤嗎? 我上的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,所以我回滾但我仍然有這個錯誤。

+0

你是如何設定的「匹配」的領域呢? –

+1

你可以發佈你的'core.0025_auto_20160120_1348'遷移文件嗎? –

回答

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默認確實已經

+0

(爲防止進一步的遷移問題,這可能需要在模型內部應用) – Sayse

+1

感謝您的幫助。這很奇怪,因爲我沒有在這個字段中使用默認屬性 – Thaian