欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

django數(shù)據(jù)庫(kù)遷移migration實(shí)現(xiàn)

 更新時(shí)間:2022年02月21日 09:35:06   作者:苗苗大佬  
這篇文章主要介紹了django數(shù)據(jù)庫(kù)遷移migration實(shí)現(xiàn),遷移任務(wù)是根據(jù)對(duì)models.py文件的改動(dòng)情況,添加或者刪除表和列,下面詳細(xì)的相關(guān)內(nèi)容需要的小伙伴可以參考一下

django中,ORM(對(duì)象關(guān)系映射器—object-relational mapper)任務(wù)是:模型化數(shù)據(jù)庫(kù),創(chuàng)建數(shù)據(jù)庫(kù)由另外一個(gè)系統(tǒng)負(fù)責(zé)(遷移–migration),遷移任務(wù)是根據(jù)對(duì)models.py文件的改動(dòng)情況,添加或者刪除表和列

依然報(bào)錯(cuò):

models.py

from django.db import models
class Item(models.Model):
? ? text=models.TextField(default='')

tests.py

'''from django.test import TestCase

# Create your tests here.
class Smokeclass(TestCase):
? ? def test_bad_maths(self):
? ? ? ? self.assertEquals(1+1,3)'''''
from ?django.urls import ?resolve
from ?django.test import ?TestCase
from lists.views import ?home_page
from django.http import ?HttpRequest
from lists.models import Item
class HomePageTest(TestCase):
? ? def test_root_url_resolve_to_home_page_view(self):
? ? ? ? found=resolve('/')
? ? ? ? # resolve函數(shù)是django內(nèi)部使用的函數(shù),用于解析url,
? ? ? ? # 并且將其映射到相應(yīng)的視圖函數(shù)上,檢查網(wǎng)站根路徑時(shí)"/",
? ? ? ? # 是否能找到home_page函數(shù)
? ? ? ? self.assertEquals(found.func,home_page)
? ? def test_home_page_returns_correct_html(self):
? ? ? ? request=HttpRequest()
? ? ? ? # 創(chuàng)建httprequest對(duì)象,用戶在瀏覽器中請(qǐng)求網(wǎng)頁(yè)時(shí)
? ? ? ? # django看到的就是httprequest對(duì)象

? ? ? ? response=home_page(request)
? ? ? ? # 把對(duì)象傳給home_page視圖

? ? ? ? html=response.content.decode('utf8')
? ? ? ? # 提取content,得到結(jié)果是原始的字節(jié),即發(fā)個(gè)用戶
? ? ? ? # 瀏覽器的0和1,隨后調(diào)用.decode(),把原始字節(jié)
? ? ? ? # 轉(zhuǎn)換成發(fā)給用戶的html字符串

? ? ? ? self.assertTrue(html.startswith('<html>'))

? ? ? ? self.assertIn('<title>To-Do lists</title>',html)

? ? ? ? self.assertTrue(html.endswith('</html>))

?self.assertTemplateUsed(response,'home.html')
? ? def test_user_home_template(self):
? ? ? ? response=self.client.get('/')
? ? ? ? self.assertTemplateUsed(response,'home.html')
? ? def test_can_save_a_POST_request(self):
? ? ? ? response=self.client.post('/',data={'item_text':'a new list item'})
? ? ? ? self.assertIn('a new list item',response.content.decode())
? ? ? ? self.assertTemplateUsed(response, 'home.html')
class ItemModelTest(TestCase):
? ? def test_saving_and_retrieving_items(self):
? ? ? ? first_item=Item()
? ? ? ? first_item.text="the first list item"
? ? ? ? first_item.save()
? ? ? ? second_item = Item()
? ? ? ? second_item.text = "the second list item"
? ? ? ? second_item.save()
? ? ? ? saved_items=Item.objects.all()
? ? ? ? self.assertEquals(saved_items.count(),2)
? ? ? ? first_saved_item=saved_items[0]
? ? ? ? second_saved_item=saved_items[1]
? ? ? ? self.assertEquals(first_saved_item.text,'the first list item')
? ? ? ? self.assertEquals(second_saved_item.text, 'the second list item')
python manage.py makemigrations

到此這篇關(guān)于django數(shù)據(jù)庫(kù)遷移migration實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)django數(shù)據(jù)庫(kù)遷移內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python實(shí)現(xiàn)圖片壓縮代碼實(shí)例

    python實(shí)現(xiàn)圖片壓縮代碼實(shí)例

    這篇文章主要介紹了python實(shí)現(xiàn)圖片壓縮代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • python中openpyxl和xlsxwriter對(duì)Excel的操作方法

    python中openpyxl和xlsxwriter對(duì)Excel的操作方法

    這篇文章主要介紹了python中openpyxl和xlsxwriter對(duì)Excel的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • python 打印對(duì)象的所有屬性值的方法

    python 打印對(duì)象的所有屬性值的方法

    下面小編就為大家?guī)?lái)一篇python 打印對(duì)象的所有屬性值的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-09-09
  • python生成遍歷暴力破解密碼的方法

    python生成遍歷暴力破解密碼的方法

    本文主要介紹了python生成遍歷暴力破解密碼的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Python中如何將Tqdm與Asyncio結(jié)合使用呢

    Python中如何將Tqdm與Asyncio結(jié)合使用呢

    這篇文章主要和大家詳細(xì)介紹了在Python中如何將Tqdm與Asyncio結(jié)合使用呢,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-05-05
  • 使用Python AIML搭建聊天機(jī)器人的方法示例

    使用Python AIML搭建聊天機(jī)器人的方法示例

    這篇文章主要介紹了使用Python AIML搭建聊天機(jī)器人的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • python自動(dòng)化測(cè)試之破解圖文驗(yàn)證碼

    python自動(dòng)化測(cè)試之破解圖文驗(yàn)證碼

    這篇文章介紹了python自動(dòng)化測(cè)試之破解圖文驗(yàn)證碼的解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • 用python擬合等角螺線的實(shí)現(xiàn)示例

    用python擬合等角螺線的實(shí)現(xiàn)示例

    這篇文章主要介紹了用python擬合等角螺線的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Python實(shí)現(xiàn)批量導(dǎo)入1000條xlsx數(shù)據(jù)

    Python實(shí)現(xiàn)批量導(dǎo)入1000條xlsx數(shù)據(jù)

    本文主要介紹了Python實(shí)現(xiàn)批量導(dǎo)入1000條xlsx數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Django框架首頁(yè)和登錄頁(yè)分離操作示例

    Django框架首頁(yè)和登錄頁(yè)分離操作示例

    這篇文章主要介紹了Django框架首頁(yè)和登錄頁(yè)分離操作,結(jié)合實(shí)例形式分析了Django框架登錄、驗(yàn)證、跳轉(zhuǎn)首頁(yè)等相關(guān)操作技巧,需要的朋友可以參考下
    2019-05-05

最新評(píng)論