Today, I encountered a puzzling BUG in the APP. After checking the code for a long time, I felt there was no problem. Finally, we had to check from the database, and it was found that there was a problem with the self-increment ID in the table. When inserting data, it would sometimes succeed or fail, because the primary key ID was repeated.

The solution is to set the increment ID to start at a certain maximum value.

Table structure query method:

    db_elone=# \d read_record;

                             Table "public.read_record"
    Column     |           Type           | Collation | Nullable |                 Default                 
---------------+--------------------------+-----------+----------+-----------------------------------------
 id            | bigint                   |           | not null | nextval('read_record_id_seq'::regclass)
 created_at    | timestamp with time zone |           |          | 
 updated_at    | timestamp with time zone |           |          | 
 deleted_at    | timestamp with time zone |           |          | 

Indexes:
    "read_record_pkey" PRIMARY KEY, btree (id)
    "idx_read_record_deleted_at" btree (deleted_at)

(END)

Copy the code
db_elone=# SELECT MAX(id) FROM read_record;   
 max  
------
 1565
(1 row)

db_elone=# SELECT setval('read_record_id_seq'.1600);  // Set this parameter to 1600
 setval 
--------
   1600
(1 row)

Copy the code

Don’t understand why this bug popped up.

= = = = = = = = = = = = = = = = = = = = = = = = = = luxuriant separation line = = = = = = = = = = = = = = = = = = = = = = = = =

Personal home page: YEE Domain

Recite the words Flutter APP: domain English APP