<tfoot id='oBGBn'></tfoot>
  • <legend id='oBGBn'><style id='oBGBn'><dir id='oBGBn'><q id='oBGBn'></q></dir></style></legend>
    <i id='oBGBn'><tr id='oBGBn'><dt id='oBGBn'><q id='oBGBn'><span id='oBGBn'><b id='oBGBn'><form id='oBGBn'><ins id='oBGBn'></ins><ul id='oBGBn'></ul><sub id='oBGBn'></sub></form><legend id='oBGBn'></legend><bdo id='oBGBn'><pre id='oBGBn'><center id='oBGBn'></center></pre></bdo></b><th id='oBGBn'></th></span></q></dt></tr></i><div id='oBGBn'><tfoot id='oBGBn'></tfoot><dl id='oBGBn'><fieldset id='oBGBn'></fieldset></dl></div>

    1. <small id='oBGBn'></small><noframes id='oBGBn'>

        • <bdo id='oBGBn'></bdo><ul id='oBGBn'></ul>

        模型中的外键(用户)

        foreignkey (user) in models(模型中的外键(用户))
          <tfoot id='XQYOG'></tfoot>
          <i id='XQYOG'><tr id='XQYOG'><dt id='XQYOG'><q id='XQYOG'><span id='XQYOG'><b id='XQYOG'><form id='XQYOG'><ins id='XQYOG'></ins><ul id='XQYOG'></ul><sub id='XQYOG'></sub></form><legend id='XQYOG'></legend><bdo id='XQYOG'><pre id='XQYOG'><center id='XQYOG'></center></pre></bdo></b><th id='XQYOG'></th></span></q></dt></tr></i><div id='XQYOG'><tfoot id='XQYOG'></tfoot><dl id='XQYOG'><fieldset id='XQYOG'></fieldset></dl></div>

                <bdo id='XQYOG'></bdo><ul id='XQYOG'></ul>
              • <legend id='XQYOG'><style id='XQYOG'><dir id='XQYOG'><q id='XQYOG'></q></dir></style></legend>

                  <small id='XQYOG'></small><noframes id='XQYOG'>

                    <tbody id='XQYOG'></tbody>
                  本文介绍了模型中的外键(用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我阅读了文档和这篇文章... Django - 用户模型的外键

                  I read the docs and this post... Django - Foreign Key to User model

                  我按照它所说的去做,但我仍然无法让它工作.当我尝试运行迁移时,我在回溯中收到此错误...

                  I followed what it said and I still cannot get it to work. When I try to run the migrations I get this error in the traceback...

                  django.db.utils.ProgrammingError: column "author_id" cannot be cast automatically to type integer
                  HINT:  You might need to specify "USING author_id::integer".
                  

                  我只是不知道如何解决这个错误.

                  I just don't know how to go about fixing that error.

                  from django.db import models
                  from django.contrib.auth.models import User
                  
                  # Create your models here.
                  class BlogCategory(models.Model):
                      '''model for categories'''
                  
                      title = models.CharField(max_length=30)
                      description = models.CharField(max_length=100)
                  
                  
                  class BlogPost(models.Model):
                      '''a model for a blog post'''
                  
                      author = models.ForeignKey(User)
                      date = models.DateField()
                      title = models.CharField(max_length=100)
                      post = models.TextField()
                  

                  推荐答案

                  我不知道settings.AUTH_USER_MODEL"方法,但是一个众所周知的方法,常用的是Auth.User"模型.像你这样的东西.

                  I do not know the "settings.AUTH_USER_MODEL" approach but a well-known approach and commonly used is the "Auth.User" model. Something like this on your end.

                  from django.contrib.auth.models import User
                  
                  class BlogPost(models.Model):
                      '''a model for a blog post'''
                  
                      author = models.ForeignKey(User)
                      date = models.DateField()
                      title = models.CharField(max_length=100)
                      post = models.TextField()
                  

                  这篇关于模型中的外键(用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <bdo id='YdPQA'></bdo><ul id='YdPQA'></ul>
                    <tfoot id='YdPQA'></tfoot>
                        <tbody id='YdPQA'></tbody>

                      1. <legend id='YdPQA'><style id='YdPQA'><dir id='YdPQA'><q id='YdPQA'></q></dir></style></legend>

                          <small id='YdPQA'></small><noframes id='YdPQA'>

                            <i id='YdPQA'><tr id='YdPQA'><dt id='YdPQA'><q id='YdPQA'><span id='YdPQA'><b id='YdPQA'><form id='YdPQA'><ins id='YdPQA'></ins><ul id='YdPQA'></ul><sub id='YdPQA'></sub></form><legend id='YdPQA'></legend><bdo id='YdPQA'><pre id='YdPQA'><center id='YdPQA'></center></pre></bdo></b><th id='YdPQA'></th></span></q></dt></tr></i><div id='YdPQA'><tfoot id='YdPQA'></tfoot><dl id='YdPQA'><fieldset id='YdPQA'></fieldset></dl></div>