Skip to content

@DatabaseField(foreign = true) doesn't generate foreign key constraints #65

@RichardForsey89

Description

@RichardForsey89

Hi, this is my first git bug report so please bear with me.

For a project I have been trying to use the annotations as per the documentation. However, when I have:

@DatabaseTable(tableName = "Profiles")
public class Profile {
@DatabaseField(generatedId = true)
    private int profile_id;
}

@DatabaseTable(tableName = "Workspaces")
public class Workspace {
@DatabaseField(generatedId = true)
    private int workspace_id;
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true, canBeNull = false)
    private Profile profile;
}

public DatabaseManager() throws SQLException, IOException {
this.databaseUrl = "jdbc:sqlite:ORMLiteTest.db";
this.connectionSource = new JdbcConnectionSource(databaseUrl);

this.profileDAO = DaoManager.createDao(connectionSource, Profile.class);
this.workspaceDAO = DaoManager.createDao(connectionSource, Workspace.class);

TableUtils.createTableIfNotExists(connectionSource, Workspace.class);
TableUtils.createTableIfNotExists(connectionSource, Profile.class);

connectionSource.close();

The resulting two tables created have their primary key, and for Workspaces, it will have the profile_id field as NOT NULL, but it won't have the Foreign Key tag set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions