English 中文(简体)
Django 很多人与许多休养关系
原标题:Django many to many recursive relationship

如果我没有很好地描述这一状况,那么我就不喜欢数据库。

I have an existing Oracle database which describes an algorithim catalogue. There are two tables algorithims and xref_alg.

Algorithims可能有父母和儿童算法。 Alg_ Xref含有与两个外国钥匙的关系——xref_alg和xref—— 父母。

这些是我迄今为止远离监察员指挥系统的Django模式。

class Algorithms(models.Model):
    alg_id = models.AutoField(primary_key=True)
    alg_name = models.CharField(max_length=100, blank=True)
    alg_description = models.CharField(max_length=1000, blank=True)
    alg_tags = models.CharField(max_length=100, blank=True)
    alg_status = models.CharField(max_length=1, blank=True)
    ...
    class Meta:
        db_table = u algorithms 

class AlgXref(models.Model):
    xref_alg = models.ForeignKey(Algorithms, related_name= algxref_alg  ,null=True, blank=True)
    xref_parent = models.ForeignKey(Algorithms, related_name= algxref_parent , null=True, blank=True)
    class Meta:
        db_table = u alg_xref 

在试图询问AlgXref时,我遇到了这种情况:

DatabaseError: ORA-00904: "ALG_XREF"."ID": invalid identifier

因此,看来错误是,它寻求的是一张主要的关键识别码,该表没有编号。 我可以提出一点,但似乎毫无意义。 是否有办法解决这一问题? 或者改变我的模式?

EDIT:在搜索线之后,Django似乎需要一种具有主要钥匙的模式。 生活太短,只是增加了一个主要的关键。 这是否会对业绩产生影响?

最佳回答

这目前是Django公司对账管理人的限制。 每个模型必须有一个领域标有<条码>、代号_key=True,如果只有一个,框架就自动设定了<条码>Auto Field 和<条码>。

然而,随着我们作为今年的谷歌《守则》暑期的一部分发言,这项工作正在进行之中,希望今年年底将在詹戈举行。 现在,你可以尝试使用https://github.com/koniiiik/django上的Djangok。 其中包含一项执行(尚未完成,但为了您的目的应当足够)。

至于是否有好处,这取决于。 这无疑使数据库更加可再使用,如果你只是增加一个自动加固的<条码>id,则造成头痛减少。 每个表格的栏目。 业绩影响太大,你可能注意到的唯一一件事是,如果你有像样的多层次表格,只包含两个<编码>ForeignKey栏,加上第三栏,其规模将增加一半。 然而,只要你不在该桌上储存数十亿row,那就毫无意义。

问题回答

暂无回答




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签