FAILED(errors = 4)销毁别名的测试数据库'默认'

时间:2017-09-20 07:50:28

标签: python django

我收到了错误,

FAILED (errors=4)
Destroying test database for alias 'default'...

我在tests.py中写道

#coding:utf-8
from django.test import TestCase
from app.models import User

# Create your tests here.
class UserModelTests(TestCase):
    def setUp(self):
        self.user1 = User.objects.create(name='Tom', group = 'A',age=20,rank=1)

    def test_user1_name(self):
        self.assertEqual(self.user1.name, 'Tom')

    def test_user1_group(self):
        self.assertEqual(self.user1.group, 'A')

    def test_user1_age(self):
        self.assertEqual(self.user1.age, 20)

    def test_user1_rank(self):
        self.assertEqual(self.user1.rank, 1)

追溯显示     ValueError:基数为10的int()的无效文字:''

models.py是

class User(models.Model):
    name = models.CharField(max_length=200,null=True)
    group = models.CharField(max_length=200,null=True)
    age = models.IntegerField(max_length=10,null=True)
    rank = models.IntegerField(max_length=10,null=True)

我无法理解为什么会发生int错误,因为我在age中使用了int类型。 我该如何解决这个问题?我该怎么写?

Full traceback is
File "/Users/myenv/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/query.py", line 393, in create
    obj.save(force_insert=True, using=self.db)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/base.py", line 806, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/base.py", line 836, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/base.py", line 922, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/base.py", line 961, in _do_insert
    using=using, raw=raw)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/query.py", line 1060, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1098, in execute_sql
    for sql, params in self.as_sql():
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1051, in as_sql
    for obj in self.query.objs
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1051, in <listcomp>
    for obj in self.query.objs
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1050, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 990, in prepare_value
    value = field.get_db_prep_save(value, connection=self.connection)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 766, in get_db_prep_save
    prepared=False)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 758, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/Users/myenv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1849, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: ''

----------------------------------------------------------------------
Ran 25 tests in 0.143s

FAILED (errors=25)
Destroying test database for alias 'default'...
(myenv) CA2641:app uu121291$ 

0 个答案:

没有答案