Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django测试:数据库中已更改的字段_Django_Django Tests - Fatal编程技术网

Django测试:数据库中已更改的字段

Django测试:数据库中已更改的字段,django,django-tests,Django,Django Tests,我正在尝试为我的应用程序运行测试,就像 django.db.utils.ProgrammingError: column "status" cannot be cast automatically to type integer HINT: Specify a USING expression to perform the conversion. 哦,这是因为我使用SQL语法将CharField更改为IntegerField(尽管迁移是为这个更改创建的) 因此,当运行test命令时,在创建测

我正在尝试为我的应用程序运行测试,就像

django.db.utils.ProgrammingError: column "status" cannot be cast automatically to type integer
HINT:  Specify a USING expression to perform the conversion.
哦,这是因为我使用SQL语法将
CharField
更改为
IntegerField
(尽管迁移是为这个更改创建的)

因此,当运行
test
命令时,在创建测试数据库时失败

有什么办法吗

更新: 现在,我将跳过使用http的第三方应用程序运行迁移的部分

现在正在创建测试表,但缓存表失败

File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 229, in sync_apps
    sql, references = connection.creation.sql_create_model(model, no_style(), seen_models)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 82, in sql_create_model
    db_params = f.db_parameters(connection=self.connection)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 548, in db_parameters
    type_string = self.db_type(connection)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/jsonfield/fields.py", line 73, in db_type
    db_type = cache.get(cache_key)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/cache/backends/db.py", line 65, in get
    "WHERE cache_key = %%s" % table, [key])
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "accounts_cache" does not exist

可以肯定的是,您已经运行了
makemigrations
migrate
,对吗?你能在这里发布迁移的文件内容吗?您能否确认
migrate
确实更改了数据库字段?如果您以用户身份进行手动测试,您是否也有相同的体验?还有更多细节要提供吗?它有点模糊。@Wtower facepalm,即使TS忘记了“migrate”DB,test命令默认情况下也会创建一个全新的数据库,考虑到所有迁移。。。无论如何,TS可以使用这个(如果版本1.8)“您可以通过添加--keepdb”来防止测试数据库被破坏,并检查迁移是否正确performed@madzohan使用--nomigrations选项(Django 1.7),它将不应用迁移,但现在缓存表出现错误,表示表不存在。嗯,听起来像是第三方包。。。找到了这个谢谢=)@madzohan别太激动伙计。试图确定是否在测试之外发生了与上述注释相同的事情。
File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 229, in sync_apps
    sql, references = connection.creation.sql_create_model(model, no_style(), seen_models)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 82, in sql_create_model
    db_params = f.db_parameters(connection=self.connection)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 548, in db_parameters
    type_string = self.db_type(connection)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/jsonfield/fields.py", line 73, in db_type
    db_type = cache.get(cache_key)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/core/cache/backends/db.py", line 65, in get
    "WHERE cache_key = %%s" % table, [key])
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/naveen/ENV/automaticfleet/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "accounts_cache" does not exist