1
以下は、移行しようとしているモデルとエラーです。私はdjango 1.10を使用しており、マイグレーションをしようとするとデータベースが空です。Django datetime.datetime to Decimalはサポートされていません。
モデル:
from django.db import models
class OrderEntry(models.Model):
quote_num = models.CharField(max_length=50, primary_key=True)
customer = models.CharField(max_length=100)
cust_po = models.CharField(max_length=50)
pdf = models.CharField(max_length=500)
datetime = models.DateTimeField(auto_now=True, editable=True, null=True)
class Items(models.Model):
quote_num = models.CharField(max_length=50, primary_key=True)
item_1 = models.CharField(max_length=100)
item_2 = models.CharField(max_length=100)
item_3 = models.CharField(max_length=100)
item_4 = models.CharField(max_length=100)
item_5 = models.CharField(max_length=100)
item_6 = models.CharField(max_length=100)
item_7 = models.CharField(max_length=100)
item_8 = models.CharField(max_length=100)
item_9 = models.CharField(max_length=100)
item_10 = models.CharField(max_length=100)
class ItemDetails(models.Model):
item = models.CharField(max_length=100, primary_key=True)
quote_num = models.CharField(max_length=50)
quan = models.CharField(max_length=100)
desc = models.TextField(max_length=1000)
price = models.DecimalField(max_digits=10, decimal_places=2, default=0, null=True)
エラー:私はpostgreデータベースに移行しようとするいくつかのデフォルトとnull値を設定している
C:\Users\Evan\Desktop\webapp>py manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, orders, sessions
Running migrations:
Applying orders.0013_itemdetails_price...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
field,
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\postgresql\schema.py", line 21, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 395, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 147, in column_sql
default_value = self.effective_default(field)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 221, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\__init__.py", line 1583, in get_db_prep_save
return connection.ops.adapt_decimalfield_value(self.to_python(value), self.max_digits, self.decimal_places)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\__init__.py", line 1554, in to_python
return decimal.Decimal(value)
TypeError: conversion from datetime.datetime to Decimal is not supported
。ご協力いただきありがとうございます。
マイグレーションを削除し、私のモデルから価格と日時フィールドを削除しました。しかし、両方のフィールドが存在しない場合、同じエラーが発生します。 – GreenSaber
移行を削除するとは、.pyファイルと.pycファイルを削除することです – e4c5