我有这个models.py class Departamento(models.Model):
id = models.AutoField(db_column='ID', primary_key=True)
nome = models.CharField(db_column='Nome', max_length=255, blank=True, null=True)
class Utilizador(AbstractBaseUser):
id = models.AutoField(db_column='ID', primar
我在Django中有一个链接和一个术语之间的多对多关系,但是当我试图检查链接和术语之间的关系是否已经存在时,我在方法上得到了一个未定义的变量。
def create_models(my_term, link):
obj, created = WikifyProjectTerms.objects.get_or_create(term = my_term)
我的模型如下:
class WikifyProjectTerms(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
term =
在Django项目中,我有以下三个模型(表):
class Tool(models.Model):
id = models.AutoField(db_column='Id', primary_key=True)
name = models.CharField(db_column='Name', unique=True, max_length=50)
class Flow(models.Model):
id = models.AutoField(db_column='Id', primary_key=True)
T
我刚从django开始,我想做一个spotify克隆。我想这样做,所以当你点击一张专辑,它会显示该专辑的歌曲。
这是我的models.py
from django.db import models
class album(models.Model):
title = models.CharField(max_length=50)
artist = models.IntegerField()
genre = models.CharField(max_length=20)
id = models.AutoField(prim
TLTR: SQL在查询中不包含数据库名,我可以强制它这样做吗?或者有解决办法?
长版本:
我有两个遗留的 MySQL 数据库(注意:我对DB布局没有影响),我是使用DRF在Django 1.11和python3.6上创建只读API
我正在通过使用这里建议的SpanningForeignKey字段来解决SpanningForeignKey DB的引用完整性限制:
我正在尝试通过DB1上的表通过ManyToMany将表连接到DB2的表。这就是Django正在创建的查询:
SELECT "table_b"."id" FROM "table_b" IN
假设我有下面这个简单的模型: class Dimdate(models.Model):
id = models.AutoField(db_column='Id', primary_key=True) # Field name made lowercase.
date = models.DateField(db_column='date') # Field name made lowercase. 此表被许多其他模型使用(因此Dimdate.id是FK),如下所示: class MyModel(models.Model):
id = models
在Django (2.x)中,我有一个输入表,模型如下:
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
class Sample(models.Model):
sample_id = models.AutoField(primary_key=True)
area_easting = models.IntegerField()
area_northing = models.IntegerField()
我在解决这个问题上遇到了麻烦,尽管我认为我理解了on_delete函数。 我有一个名为Project的模型和一个名为UserProject的模型。在Userproject中,我有两个外键,分别指向一个用户和一个项目。 我尝试的是在项目外键上使用on_delete = CASCADE。这似乎只影响Userproject模型中的Project-field。因此,当我删除一个也有Userproject条目的项目时,这些条目不会被删除。我怎样才能做到这一点呢? from django.db import models
from django.contrib.auth.models import Us
from django.db import models
from django.contrib.auth.models import User
class Transfer(models.Model):
id = models.AutoField(primary_key=True)
amount = models.DecimalField(max_digits=10, decimal_places=2)
name=models.CharField(max_length=55)
timestamp = models.DateTimeField(auto_now_a
我正在尝试使用python/django和postgres创建表。我为models.py中的每个数据库表创建类。当我尝试创建迁移时,它会给出以下错误:
File "..\database\models.py", line 40, in <module>
class group(models.Model):
File "database\models.py", line 41, in group
user_id = models.ForeignKey(user) TypeError: __init__() missing 1 requi
当我在python3 manage.py shell中删除这些行时:
In [1]: from dream_site.models import Mentor, Mentee, Team
In [2]: a = Mentee.objects.get( pk = 1 ).name
In [3]: b = Mentor.objects.get(pk=1).name
In [4]: print( a + b )
它按预期打印适当的输出,但是在models.py中,当我有以下代码时,它会给出int() argument must be a string or a number错误:
def __str
在创建父模型时,如何使用related_name创建子模型。
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
class Parent(models.Model):
name = models.TextField()
child = models.ForeignKey(Child, on_delete=models.SET_NULL, related_name="par
我正在从多个表中获取数据,以便在模板中显示,但是获得相同的类型错误。请帮我找出错误。
Models.py
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
# Create your models here.
class quiztitle(models.Model):
Quiz_id = models.AutoField(primary_key=True)
Quiz_title = models.CharFiel
我有以下Django模型:
class Book(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200)
class Meta:
db_table = "books"
class BookCategory(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=50
我有django的模型,通过ForeignKey有很多很多:
class A(m.Model):
id = m.AutoField(primary_key=True)
name = m.CharField(max_length=250, unique=True, null=False)
def __str__(self):
return self.name
class B(m.Model):
id = m.AutoField(primary_key=True)
name
我有两张桌子,是作者和书。
在作者表中,我有'id‘和'name’字段。
在书表中,我有'book_id‘和’author_id‘(外键)。
下面是我的数据库中的sql statement.It工作。
select "Author"."Name",count("BookId")
from "Author"
join "Book" on "Book"."AuthorId" = "Author"."Id"
group by "
我有两个简单的模型,一个代表电影,另一个代表电影的评级。
class Movie(models.Model):
id = models.AutoField(primary_key=True)
title = models.TextField()
class Rating(models.Model):
id = models.AutoField(primary_key=True)
movie = models.ForeignKey(Movie)
rating = models.FloatField()
我的期望是,我将能够首先创建引用该电影的Movi
我有两张桌子
Class Billing(models.Model):
id=models.AutoField(primary_key=True)
.....
#Some more fields
....
Class BillInfo(models.Model):
id=models.AutoField(primary_key=True)
billing=models.ForeignKey(Billing)
testId=models.ForeignKey(AllTests)
costOfTest=models.IntegerField(default=0)
c
我必须为active MySQL数据库创建一个简单的CRUD面板。当我试图迁移我的应用程序时,我会收到以下错误:
AssertionError: A model can't have more than one Autofield
我在Django书第18章中读到了以下内容:
每个生成的模型对于每个字段都有一个属性,包括id主键字段。但是,请记住,如果模型没有主键,Django会自动添加id主键字段。因此,您需要删除如下所示的任何行:
id = models.IntegerField(primary_key=True)不仅这些行是多余的,而且如果您的应用程序要向这些表中添加新的记录,
我使用的是一个遗留数据库,它以db的方式做了一些有意义的事情,但不确定如何在Django中表示它们,以便South和Django本身可以处理它们。
我有一个以PartCode为键的零件表,我有一个以VendorCode为键的供应商表
我有一个FK's to Parts和Vendor的PartsVendor表,以及关于关系的附加信息。我使用了"through“参数,所以它是独立的,但是它使用PartCode+VendorCode作为组合键,这在Django中是不支持的。只有当使用South或者像dumpdata这样的函数来查看主键时,我才会遇到问题。然而,这些都是相当大的问题。