簡體   English   中英

創建models.py時發現row size太大問題,如何解決

[英]When creating models.py ,the row size too large issue is found ,how to solve this problem

如何解決這個問題:

raise errorclass(errno, errval) django.db.utils.InternalError: (1118, u'Row size too large. 所用表類型的最大行大小,不包括 BLOB,為 65535。這包括存儲開銷,請查看手冊. 您必須將某些列更改為 TEXT 或 BLOB')

請幫忙解決這個問題,這里是 model 代碼:

from django.db import models

class Newsdeatils(models.Model):
    news_provider_id = models.CharField(max_length=5000)
    news_title =  models.CharField(max_length=5000)
    news_details = models.CharField(max_length=5000)
    news_image = models.CharField(max_length=5000)
    news_page_url = models.CharField(max_length=5000)
    next_page = models.CharField(max_length=5000)
    news_des = models.CharField(max_length=5000)

只需使用TextField來滿足這樣的長度要求。

通常,TextFields 並不真正限於特定長度 w.r.t。 實現限制(關於文件系統或使用的通用數據庫系統)。 TextFields在使用上與CharFields非常相似。 您可以在此處閱讀不同之處。

你的代碼會變成這樣:

from django.db import models

class Newsdeatils(models.Model):
    news_provider_id = models.TextField(max_length=5000)
    news_title =  models.TextField(max_length=5000)
    news_details = models.TextField(max_length=5000)
    news_image = models.TextField(max_length=5000)
    news_page_url = models.TextField(max_length=5000)
    next_page = models.TextField(max_length=5000)
    news_des = models.TextField(max_length=5000)

請注意,不需要在TextField上設置max_length屬性(這是在使用CharField時)。 max_length屬性也未在 db 級別強制執行,但僅用於表單驗證。

model 中要考慮的其他事項: 為什么news_provider_idCharField 那不應該是ForeignKey嗎? 類似news_image字段的內容也是如此。 這可能應該是BinaryField

I get answer ,the issue   was  i had given all fields as 5000 as max_length , A table contain only limited size and i alter the column size  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM