- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Missing Table When Running Django Unittest with Sqlite3
我已经看过这篇文章,并正在尝试设置我的项目进行测试。每当我尝试运行任何数据库命令时,都会出现错误。我遇到的问题是,当我尝试执行 manage.py syncdb 时,我收到一个数据库错误,说即使它当前位于模型文件和生产数据库中,也不存在这样的表。
这是追溯。
brandon@Brandon-PC:~/course-management$ ./manage.py test Testing.SimpleTest
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/South-0.7.3-py2.7.egg/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/core/management/commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/test/simple.py", line 358, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/test/simple.py", line 245, in build_suite
suite.addTest(build_test(label))
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/test/simple.py", line 107, in build_test
app_module = get_app(parts[0])
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 129, in get_app
self._populate()
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/brandon/course-management/Course/models.py", line 223, in <module>
class CourseDelivery(models.Model):
File "/home/brandon/course-management/Course/models.py", line 262, in CourseDelivery
Language = models.ForeignKey('Utilities.Language', default=Language.objects.get(Code='en'))
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/query.py", line 344, in get
num = len(clone)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/Django-1.3.1-py2.7.egg/django/db/backends/sqlite3/base.py", line 234, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: Utilities_language
if 'test' in sys.argv or 'jenkins' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test_ndptc'
}
}
class CourseDelivery(models.Model):
"""
"""
Course = models.ForeignKey(Course)
TrainingMethod = models.ForeignKey(TrainingMethod)
DeliveryType = models.ForeignKey(DeliveryType)
Location = models.ForeignKey(Address, null=True)
Lat = models.FloatField()
Lon = models.FloatField()
StartDate = models.DateTimeField()
EndDate = models.DateTimeField()
FinishDate = models.DateField(null=True)
ConfirmationCode = models.CharField(max_length=8, editable=False, unique=True)
Reported = models.BooleanField()
ReportedDate = models.DateField(null=True)
SequenceNumber = models.IntegerField(null=True)
Status = models.IntegerField()
HostingAgency = models.TextField(null=True, blank=True)
MaximumEnrollment = models.IntegerField(null=True, blank=True)
ContactInformation = models.TextField(null=True, blank=True)
ArrivalTime = models.TextField(null=True, blank=True)
CourseMaterials = models.TextField(null=True, blank=True)
Internet = models.TextField(null=True, blank=True)
Food = models.TextField(null=True, blank=True)
Parking = models.TextField(null=True, blank=True)
Requirements = models.TextField(null=True, blank=True)
AdditionalInformation = models.TextField(null=True, blank=True)
ReadingMaterials = models.TextField(null=True, blank=True)
SpecialNote = models.TextField(null=True, blank=True)
CertificateEmailsSent = models.BooleanField(default=False)
RegistrationCloseDate = models.DateTimeField(null=True, blank=True)
ReminderDate = models.DateTimeField(null=True, blank=True)
PreTestCloseDate = models.DateTimeField(null=True, blank=True)
PostTestCloseDate = models.DateTimeField(null=True, blank=True)
EvaluationCloseDate = models.DateTimeField(null=True, blank=True)
ParticipantGuide = models.ForeignKey('Course.Document', null=True, blank=True)
Flyer = models.FileField(upload_to='flyers/%Y/%m', null=True, blank=True)
UpdateUser = models.ForeignKey(User, null=True)
UpdateDate = models.DateField(null=True)
Language = models.ForeignKey('Utilities.Language', default=Language.objects.get(Code='en'))
def save(self):
# If this is the first time around, or AUTO_COMPUTE_DATES is true, compute the dates.
if self.Status & CourseDeliveryStatus.AUTO_COMPUTE_DATES:
self.RegistrationCloseDate = self.StartDate - datetime.timedelta(days=REGISTRATION_CLOSE_DATE)
self.ReminderDate = self.StartDate - datetime.timedelta(days=REMINDER_DATE)
self.PreTestCloseDate = self.StartDate - datetime.timedelta(days=PRE_TEST_CLOSE_DATE)
self.PostTestCloseDate = self.EndDate + datetime.timedelta(days=POST_TEST_CLOSE_DATE)
self.EvaluationCloseDate = self.EndDate + datetime.timedelta(days=EVALUATION_CLOSE_DATE)
self.FinishDate = self.EndDate + datetime.timedelta(days=FINISH_DATE)
elif self.id == None:
if not self.RegistrationCloseDate:
self.RegistrationCloseDate = self.StartDate - datetime.timedelta(days=REGISTRATION_CLOSE_DATE)
if not self.ReminderDate:
self.ReminderDate = self.StartDate - datetime.timedelta(days=REMINDER_DATE)
if not self.PreTestCloseDate:
self.PreTestCloseDate = self.StartDate - datetime.timedelta(days=PRE_TEST_CLOSE_DATE)
if not self.PostTestCloseDate:
self.PostTestCloseDate = self.EndDate + datetime.timedelta(days=POST_TEST_CLOSE_DATE)
if not self.EvaluationCloseDate:
self.EvaluationCloseDate = self.EndDate + datetime.timedelta(days=EVALUATION_CLOSE_DATE)
if not self.FinishDate:
self.FinishDate = self.EndDate + datetime.timedelta(days=FINISH_DATE)
# If the course does not have a code, create one.
if not self.ConfirmationCode:
self.ConfirmationCode = ''.join(Random().sample(string.digits, 5))
#Course.functions.geocode_course_delivery(self)
super(CourseDelivery, self).save()
def __unicode__(self):
return unicode(self.StartDate.strftime('%m/%d/%Y')) + ' - ' + self.Course.CourseName \
+ ' (' + unicode(self.Location.City) + ', ' + unicode(self.Location.State) + ')'
def registration_date_passed(self):
today = datetime.date.today()
if today > self.RegistrationCloseDate.date():
return True
return False
def registration_open(self):
# Do not allow registrations after the course has been reported.
if self.Reported:
return False
# Check that the closing dates and enrollment are good.
today = datetime.date.today()
if self.Status & CourseDeliveryStatus.ONLINE_REGISTRATION:
if self.RegistrationCloseDate.date() < today:
return False
# Make sure that the MaximumEnrollment is greater than the participant count
if not self.wait_list_enabled() and self.MaximumEnrollment:
participant_count = Participant.objects.filter(CourseDelivery=self).count()
if not self.MaximumEnrollment - participant_count > 0:
return False
return True
return False
def wait_list_enabled(self):
if self.Status & CourseDeliveryStatus.WAIT_LIST:
return True
return False
def get_form(self, form_type):
package = CourseDeliveryForms.objects.filter(CourseDelivery=self.id).get(FormType=form_type).FormPackage
__import__(package.FormModule)
return eval(package.FormName)
def get_model(self, form_type):
package = CourseDeliveryForms.objects.filter(CourseDelivery=self.id).get(FormType=form_type).FormPackage
__import__(package.ModelModule)
return eval(package.ModelName)
def get_template(self, form_type):
package = CourseDeliveryForms.objects.filter(CourseDelivery=self.id).get(FormType=form_type).FormPackage
return package.Template
def default_language(self):
return Language.objects.get(Code='en')
最佳答案
我也有这个问题。原来我必须在 settings.py 文件中添加一个 TEST_NAME 属性才能正确识别测试数据库。它为我解决了这个问题:
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
'TEST_NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
}
}
关于python - 使用 sqlite3 db 缺少表的单元测试 django 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10840115/
我正在尝试在 map 上绘制一些疾病事件数据的位置。 我用它来导入数据: ByTown% addProviderTiles("CartoDB.Positron")%>% addPolygons
我有一个文件调用 find.js,我使用 node find.js 运行,我的节点是版本 10 我不知道为什么我无法使用 async await。 const axios = require("axi
我有一个项目作为引用添加到 System.Web。 但是,它似乎无法获取 HttpContext。这样做: Imports System.Web _ApplicationBase = HttpCont
在互联网上找到这段代码,出于某种原因它缺少 while 循环逻辑“while(i....)”,虽然我找到了 PigLatin* 问题的其他可行解决方案,但我真的很想了解这个正在工作。 *PigLati
我工作了一整天来运行 Xampp 并在其上安装 TYPO3。现在我登录到后端,但没有显示许多管理模块,例如模板、访问等。 - 一定是我做错了什么,但我不知道。 these are the module
你好 我有编译这个问题 \begin{equation} J = \sum_{j=1}^{C} \end{equation} 我不断收到错误 missing $ inserted 这很奇怪,因
我正在尝试使用 SQLite CLI,但无法获得 generate_series功能来工作。我可以按照文档中的建议使用递归 CTE 对其进行模拟,但我似乎无法获得该链接中的任何示例。这是我的 sess
我目前正在开发我想要的软件,而软件正在安装,它可以在后台为软件创建 native 图像。 我正在考虑使用 NGEN 并将进程优先级设置为低,因为我不希望它消耗 100% CPU。但是我发现我的计算机上
我想使用 Xcodes Instruments 进行 UI 自动化测试。但似乎缺少“自动化”。我怎样才能添加这个? 最佳答案 如果您想使用自动化仪器,请使用 Xcode 7.3。 Apple 在 Xc
我目前在 JS 开发中迈出了一小步,并编写了以下链接添加器: const button = document.getElementById('button') const listdiv = docu
此代码有什么问题: NSError *error = nil; [SFHFKeychainUtils deleteItemForUsername:@"IAPNoob01" andServiceName
出于某种原因,在安装和配置(我认为)一切之后,com.adobe.utils.AGALMiniAssembler 不见了,其他一切正常。 我认为我已尽一切努力让孵化器正常工作,但显然我错过了一步。 如
我有一个名为 new 的方法。调用 new 时,我传递了一个参数,但是当我运行应用程序时,出现没有参数或参数为空的错误。 StepReader.pm package StepReader; use s
安装 gtk 1.2(包名 gtk1)和 macports chokes 在最终的 make 中,在 libintl.h 的第 440 行。 extern locale_t libintl_newlo
我用按钮创建表格。 这是javascript代码: function layersListTable(layers) { var content =''; $.each($(layer
我在使用此 javascript 时遇到此错误,任何人都可以帮我弄清楚我做错了什么吗? $(this).prepend('Check availability »'); 它给我错误 mis
我有一个独立的工具链 NDK13b、api19、llvm 3.8 编译器、arm 32 位、带有 libcpp(llvm C++ 库) 我想避免依赖 libgcc,所以我构建了 compiler-rt
我按照一些教程使用 phonegap 的条形码扫描器插件。但是当我从现有源创建一个新的 android 项目来创建条码库时 (step 6 in this page)我收到错误:“AndroidMan
我现在尝试在 Eclipse 中打开我的布局 xml 文件。我只得到错误 No XML content. Please add a root view or layout to your docume
我的 android-sdk-windows\tools 目录中缺少层次结构查看器工具。 工具链接: http://developer.android.com/guide/developing/too
我是一名优秀的程序员,十分优秀!