Django:迁移不支持datetime.datetime到Decimal

时间:2015-10-19 16:50:24

标签: python django

我使用的是Django 1.9 alpha(或1.8,效果相同)和Python 3.4.3。我有一个下面列出的基本型号。我试图使用创建和填充数据库迁移的新方法。

from django.db import models

class services(models.Model):
    service = models.CharField(max_length=150)
    type = models.CharField(max_length=150)
    purchase_date = models.DateField('purchase date')
    renew_date = models.DateField('renew date')
    end_date = models.DateField('end date')
    price = models.DecimalField(max_digits=8, decimal_places=2,     null=True, blank=True)
    supplier = models.CharField(max_length=100)
    variant = models.CharField(max_length=200)
    web_link = models.URLField(verbose_name="web link", null=True, blank=True)

一旦我制作了“makemigrations'然后'迁移'我收到一个错误。我真的可以找到任何参考Django文档甚至在谷歌。

你知道出了什么问题吗?我在2台不同的PC上做过(我以为这是Django / Python的错误),但没有运气。

错误:

python manage.py migrate

> Operations to perform:   Apply all migrations: sessions, admin, auth,
> contenttypes, extservices Running migrations:   Rendering model
> states... DONE   Applying
> extservices.0002_auto_20151018_1742...Traceback (most recent call las
> t):   File "manage.py", line 10, in <module>
>     execute_from_command_line(sys.argv)   File "C:\Python34\lib\site-packages\django\core\management\__init__.py",
> line 350, in execute_from_command_line
>     utility.execute()   File "C:\Python34\lib\site-packages\django\core\management\__init__.py",
> line 342, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)   File "C:\Python34\lib\site-packages\django\core\management\base.py", line
> 348,  in run_from_argv
>     self.execute(*args, **cmd_options)   File "C:\Python34\lib\site-packages\django\core\management\base.py", line
> 399,  in execute
>     output = self.handle(*args, **options)   File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
> ", line 200, in handle
>     executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)   File
> "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line
> 92 , in migrate
>     self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_ini tial)   File
> "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line
> 12 1, in _migrate_all_forwards
>     state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_ initial)   File
> "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line
> 19 8, in apply_migration
>     state = migration.apply(state, schema_editor)   File "C:\Python34\lib\site-packages\django\db\migrations\migration.py",
> line 1 23, in apply
>     operation.database_forwards(self.app_label, schema_editor, old_state, projec t_state)   File
> "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py"
> , line 62, in database_forwards
>     field,   File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py",
> lin e 221, in add_field
>     self._remake_table(model, create_fields=[field])   File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py",
> lin e 103, in _remake_table
>     self.effective_default(field)   File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py",
> line 2 10, in effective_default
>     default = field.get_db_prep_save(default, self.connection)   File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py",
> line  1628, in get_db_prep_save
>     return connection.ops.adapt_decimalfield_value(self.to_python(value),   File
> "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py",
> line  1599, in to_python
>     return decimal.Decimal(value) 
> TypeError: conversion from datetime.datetime to Decimal is not supported

0 个答案:

没有答案