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.

autoincrement=true

See original GitHub issue

When using autoincrement on a primary key field

example:

@PrimaryKey (autoincrement=true) long id;

it appears the counter is getting reset when items are deleted. In other words, available ID’s lower than the MAX ID in a table are being re-used. It appears DB flow is managing its own internal autoincrement value?

In a scenario of insert record a, b, c. Their IDs become 1,2,3 respectively. If I remove item c and add item d I would expect item d’s ID to be 4, but its not, its 3.

Is this the desired behaviour?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
fish-4-funcommented, Feb 14, 2016

Here is an example of the class. Appreciate you looking into this…

To remove (delete) I just call someInstance.delete();

If I remove all items in the table, the next insert starts with an ID of 0.

`package com.fish4fun.myapp.models;

import android.util.Log;

import com.raizlabs.android.dbflow.annotation.Column; import com.raizlabs.android.dbflow.annotation.ModelContainer; import com.raizlabs.android.dbflow.annotation.PrimaryKey; import com.raizlabs.android.dbflow.annotation.Table; import com.raizlabs.android.dbflow.structure.BaseModel;

import java.io.File;

@ModelContainer @Table(database = MyAppDatabase.class) public class SomeEntity extends BaseModel {

@PrimaryKey(autoincrement = true)
long id;

@Column
int order;

@Column
String name;

@Column
String filename;

@Column
String code;

@Column
String type;

@Column
int color;

@Column
long created;

@Column
long modified;

public SomeEntity() {
    super();
}

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

more getters and setters… }`

0reactions
agrosnercommented, Mar 2, 2016

in develop

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to create autoincrementing primary key with flask ...
If you are wanting an auto-incrementing id field for a composite key (ie. more than 1 db.Column(..) definition with primary_key=True , then ...
Read more >
How to set a auto-increment value in SQLAlchemy?
I want to set a autoincrement value from 1000. How do I do it? postgresql · python · orm · sqlalchemy · Share....
Read more >
Defining an Auto Increment Primary Key in PostgreSQL - Chartio
For a relational database like PostgreSQL, it could widely be considered a sin among developers not to include a primary key in every...
Read more >
Setting the starting value of an autoincrement field?
autoincrement = True, autoincrementstart = 10000) ... I'm learning that the autoincrement support across databases is a bit
Read more >
AutoIncrement Property - Business Central - Microsoft Learn
True if the field value is automatically incremented; otherwise, false. The default value is false. Note. If you want to manually assign a...
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