Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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
Mysql Django测试Django.db.utils.ProgrammingError:(1146,“Table';db.Table';不存在”)_Mysql_Django_Rest_Unit Testing_Django Rest Framework - Fatal编程技术网

Mysql Django测试Django.db.utils.ProgrammingError:(1146,“Table';db.Table';不存在”)

Mysql Django测试Django.db.utils.ProgrammingError:(1146,“Table';db.Table';不存在”),mysql,django,rest,unit-testing,django-rest-framework,Mysql,Django,Rest,Unit Testing,Django Rest Framework,我在Django中运行一个简单的测试用例,我有一个模型订阅服务器,但当我运行python manage.py测试时 它给了我以下的错误 Creating test database for alias 'default'... System check identified no issues (0 silenced). E ====================================================================== ERROR: test_sub

我在Django中运行一个简单的测试用例,我有一个模型订阅服务器,但当我运行
python manage.py测试时
它给了我以下的错误

Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: test_subscriber_fullname 
(gatpulsecore.tests.test_models.SubscribersTest)
Test method get_fullname
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\cursors.py", line 170, in execute
    result = self._query(query)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\cursors.py", line 328, in _query
    conn.query(q)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\connections.py", line 516, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\connections.py", line 727, in _read_query_result
    result.read()
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\connections.py", line 1066, in read
    first_packet = self.connection._read_packet()
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\connections.py", line 683, in _read_packet
    packet.check_error()
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "C:\Users\dania\AppData\Local\Programs\Python\Python36\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1146, "Table 'test_gatpulsedevinstance.subscribers' doesn't exist")
我的模型看起来像这样

from django.db import models

class Subscribers(models.Model):
    """ Subscriber Model """   
    idsubscribers = models.AutoField(primary_key=True)
    legalid = models.CharField(max_length=45, blank=True, null=True)
    name = models.CharField(max_length=45, blank=True, null=True)
    lastname = models.CharField(max_length=45, blank=True, null=True)
    initialdate = models.DateField(blank=True, null=True)
    bday = models.DateField(blank=True, null=True)
    email = models.CharField(max_length=100, blank=True, null=True)
    phone = models.CharField(max_length=45, blank=True, null=True)
    emergencyphone = models.CharField(max_length=45, blank=True, null=True)
    photolink = models.CharField(max_length=200, blank=True, null=True)
    medicalconditions = models.CharField(max_length=200, blank=True, null=True)
    objectives = models.CharField(max_length=200, blank=True, null=True)
    paymentfrequency = models.CharField(max_length=45, blank=True, null=True)

    def get_fullname(self):
        return self.name + " " + self.lastname
    class Meta:
        managed = False
        db_table = 'subscribers'
还有我的测试文件

from django.test import TransactionTestCase
from gatpulsecore.models import Subscribers

class SubscribersTest(TransactionTestCase):
    """ Test module for Subscribers model """

    def setUp(self):
        Subscribers.objects.create(
            legalid='34214555', name='Casper', lastname='Smith')
        Subscribers.objects.create(
            legalid='24612555', name='John', lastname='Rogers')

    def test_subscriber_fullname(self):
        """ Test method get_fullname """
        sub_casper = Subscribers.objects.get(name='Casper')
        sub_john = Subscribers.objects.get(name='John')
        self.assertEqual(
            sub_casper.get_fullname(), "Casper Smith")
        self.assertEqual(
            sub_john.get_fullname(), "John Rogers")
我已经尝试过迁移,但没有帮助,也有人建议使用TransactionTestCase而不是TestCase,但也不起作用。
有人遇到过同样的错误吗?我一直在寻找解决方法,但似乎没有找到任何有用的方法。

如果您使用多个数据库,则可能会发生这种情况,在这种情况下,您必须使用以下方法指定数据库:

MyModel.objects.using("database_name")
或者简单地将特定数据库指定为主数据库


据我所知,django没有检测到您的数据库,或者您有多个数据库。

我明白了,奇怪的是,我在settings.py中只注册了一个数据库,并且指定数据库都不起作用,谢谢