Probably because the 1st field of the record is the primary key and already indexed.
IE no need to create an index for the 1st field in the record definition.
The index property is for secondary indexes.
From the docs: index. This is a list of attribute names, or integers, which specify the tuple positions on which Mnesia is to build and maintain an extra index table.
and a little further down
For information about the complete set of table properties and their details, see mnesia:create_table/2.
This Reference Manual uses a table of persons to illustrate various examples. The following record definition is assumed:
age = 0,
address = unknown,
salary = 0,
children = }),
The first record attribute is the primary key, or key for short.
In your first example, the primary key is id, and you are trying to create an additional index on the id field. Mnesia returns an error because it is unnecessary and redundant.
In your second example, you rearranged the record fields so that id is no longer the primary key. Instead, it becomes an additional field that you can create an index on. That’s why the second example works.