As you have a layer that could be edited, it is a PostGIS layer. To get a primary with PostGIS you can not use the attribute form control in QGIS, you must define it within the DB manager.
Step 1 : create the DB table with primary key
The easiest way is to use a layer you have in your computer and import it in PostGIS. You have to prepare your layer and change attribute name to get no space in it (you could get some strange result if not). The import vector layer toolbox will let you choose the field name used for primary key or to create one (if you choose a field name that doesn't exist in your layer).
This will create a layer in PostGIS database that has a primary key. If you use the DB manager and reconnect to your DB and open the info of your table you should see two things :
- in the fields, one have Null =
N and Default field.
- You should see a constraints type primary key
Step 2 option A : add default value for time
You can define the default value in DB or in QGIS form proprieties (answered before).
To define it in the DB you have to use the SQL querry windows and add a default value expression (warning, SQL expression is not the same as QGIS expression).
Here is an example for time attribute (the field have to be created before) :
ALTER TABLE "schema_name"."table_name" ALTER COLUMN "time" SET DEFAULT now();
As well, you can define a default value for a field named user.
Step 2 option B : Use logging of every change done by users
In QGIS database manager, there is the tool "Change logging" to log every change made in the database and keep history of modification.
This tool will add username, start_date and end_date automatically. But to use it, you have to empty your database then use the tool with default option.
This will modify your current table (add new fields and triggers and rules) and create a new table named TABLENAME_current.
Then add the layer to your project, activate a filter
"time_end" is NULL and copy all your features in this layer. Each modification will create a new feature and add a time end to the old feature. In the form you can hide : id_hist, id, time_end, time_start, user_role