question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent foreign key column names from appending _id

See original GitHub issue

DBFlow Version: 4.0.0-beta5 Issue Kind (Bug, Question, Feature): Question

Description: For foreign key references How can I prevent foreign id names from appending _id at the end?

For example, I have 2 classes like this: organization class:

@Table(database = MyDatabase.class)
public class organization extends BaseModel {
    @Column
    @PrimaryKey
    int id;

    @Column
    String name;

   // getters and setters

}

college class:

@Table(database = MyDatabase.class)
public class college extends BaseModel {
    @Column
    @PrimaryKey
    int id;

    @Column
    String name;

    @Column
    @ForeignKey(tableClass = organization.class)
    int foo;

   // getters and setters

}

But, when I compile, the name foo becomes foo_id in the database as well as college_Table class.

Setting @Column(name=“foo”) also doesn’t work. It failes at the compile time only. And gives the following error:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.util.MissingFormatArgumentException: Format specifier '%1s'

Is there any way I can prevent this behavior and keep the same name foo?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
agrosnercommented, Mar 21, 2017

Ill keep this open as a reminder 😃

2reactions
agrosnercommented, Mar 21, 2017

if you have multiple primary keys:

@ForeignKey(references = {
    @ForeignKeyReference(columnName = "foo", foreignKeyColumnName = "id'),
    @ForeignKeyReferece(columnName="otherfoo", foreignKeyColumnName="id2"})
organization org;

where:

@Table(database = MyDatabase.class)
public class organization extends BaseModel {
    @PrimaryKey
    int id;

    @PrimaryKey
    int id2;

    @Column
    String name;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core, disable foreign key column name generation
I corrected issue by adding ForeignKey attribute to Book class. I borrowed the answer from: The required column 'CustomerId' was not present ...
Read more >
3 common foreign key mistakes (and how to avoid them)
Dangling foreign keys 3. Not creating foreign key indexes Bonus: Not using foreign keys Key takeaway: think before you CREATE TABLE.
Read more >
Documentation: 15: 5.4. Constraints - PostgreSQL
You can assign your own name for a foreign key constraint, in the usual way. A foreign key can also constrain and reference...
Read more >
13.1.18.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
The table must have the correct column names and types. It must also have indexes on the referenced keys. If these requirements are...
Read more >
Keys - EF Core | Microsoft Learn
Configuring a primary key; Value generation; Primary key name; Key types and values; Alternate Keys. A key serves as a unique identifier for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found