我正在学习使用Django,当我执行" migrate"时出现错误。我正在使用DateTimeField错误:
Operations to perform: Apply all migrations: admin, contenttypes, sessions, auth, principal Running migrations: Applying principal.0002_auto_20140910_1459.../Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/models/fields/__init__.py:1350: RuntimeWarning: DateTimeField Producto.tiempo_registro received a naive datetime (2014-09-10 00:00:00) while time zone support is active. RuntimeWarning)
Traceback (most recent call last): File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/core/management/__init__.py", line 336, in execute_from_command_line
utility.execute() File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/core/management/__init__.py", line 328, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/core/management/base.py", line 369, in run_from_argv
self.execute(*args, **cmd_options) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/core/management/base.py", line 419, in execute
output = self.handle(*args, **options) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/core/management/commands/migrate.py", line 193, in handle
executor.migrate(targets, plan, fake=options.get("fake", False)) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/migrations/operations/fields.py", line 37, in database_forwards
field, File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/backends/sqlite3/schema.py", line 160, in add_field
self._remake_table(model, create_fields=[field]) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/backends/sqlite3/schema.py", line 74, in _remake_table
self.effective_default(field) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/backends/schema.py", line 189, in effective_default
default = field.get_db_prep_save(default, self.connection) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/models/fields/related.py", line 1774, in get_db_prep_save
return self.related_field.get_db_prep_save(value, connection=connection) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/models/fields/__init__.py", line 632, in get_db_prep_save
prepared=False) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/models/fields/__init__.py", line 913, in get_db_prep_value
value = self.get_prep_value(value) File "/Library/Python/2.7/site-packages/Django-1.8.dev20140910084412-py2.7.egg/django/db/models/fields/__init__.py", line 921, in get_prep_value
return int(value) TypeError: int() argument must be a string or a number, not 'datetime.date'
但是,如果我对该行发表评论并且做了#34;迁移&#34;我犯了同样的错误。
粘贴models.py:
#encoding:utf-8
from django.db import models
from django.contrib.auth.models import User
class Producto(models.Model):
nombre = models.CharField(max_length=50)
#precio = models.DecimalField(max_digits=10, decimal_places=2, help_text='Con solo dos decimales')
#imagen = models.ImageField(upload_to='productos', verbose_name='Imagen producto', null=True)
#fecha_registro = models.DateTimeField('date published')
#usuario = models.ForeignKey(User, blank=True)
def __str__(self):
return self.nombre
由于