Skip to content

composite_index with id breaks relation #170

@andreymal

Description

@andreymal
from datetime import datetime
from pony.orm import *

db = Database()

class Comment(db.Entity):
    id = PrimaryKey(int, auto=True)
    parent = Optional('Comment')
    date = Required(datetime, default=datetime.utcnow)
    text = Required(LongStr)
    answers = Set('Comment')
    composite_index(id, date)  # comment it and all will work

db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)
sql_debug(True)

with db_session:
    Comment(text='foo')

pony.orm.core.CommitException: Object Comment[new:1] cannot be stored in the database. OperationalError: foreign key mismatch - "Comment" referencing "Comment"

Without composite_index field id is "id" INTEGER PRIMARY KEY AUTOINCREMENT. With composite_index"id" INTEGER NOT NULL.

I don't know, maybe id with composite_index is stupid, but pony should be something to do with it :)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions