Issue: pwiz not importing primary key in model
Author: mudasirmirza
State: closed
Created: 2020-12-02 23:01:55

Hey all,

I using pwiz to create a model from mysql database and unable to figure out why the primary key column `id` is not being added in the model

When I run this command
`python -m pwiz -o -e mysql -u root -P myapp -t reviews`

I get the below output

```
class UnknownField(object):
    def __init__(self, *_, **__): pass

class BaseModel(Model):
    class Meta:
        database = database

class Reviews(BaseModel):
    type = CharField(index=True, null=True)
    product_owner = IntegerField(constraints=[SQL("DEFAULT 0")], index=True, null=True)
    product_id = IntegerField(index=True, null=True)
    userid = CharField(index=True, null=True)
    rating = CharField(index=True, null=True)
    name = CharField(null=True)
    email = CharField(null=True)
    message = TextField(null=True)
    status = IntegerField(constraints=[SQL("DEFAULT 1")], null=True)
    date_time = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")], null=True)

    class Meta:
        table_name = 'reviews'
```

And when I describe the table with `desc reviews` I get the below output

```
mysql> desc reviews;
+---------------+--------------+------+-----+-------------------+----------------+
| Field         | Type         | Null | Key | Default           | Extra          |
+---------------+--------------+------+-----+-------------------+----------------+
| id            | int(11)      | NO   | PRI | NULL              | auto_increment |
| type          | varchar(255) | YES  | MUL | NULL              |                |
| product_owner | int(25)      | YES  | MUL | 0                 |                |
| product_id    | int(11)      | YES  | MUL | NULL              |                |
| userid        | varchar(255) | YES  | MUL | NULL              |                |
| rating        | varchar(255) | YES  | MUL | NULL              |                |
| name          | varchar(255) | YES  |     | NULL              |                |
| email         | varchar(255) | YES  |     | NULL              |                |
| message       | longtext     | YES  |     | NULL              |                |
| status        | int(11)      | YES  |     | 1                 |                |
| date_time     | datetime     | YES  |     | CURRENT_TIMESTAMP |                |
+---------------+--------------+------+-----+-------------------+----------------+
```

I can see that there is a primary key named ```id``` which is not being added in the model. How can I get the primary key in the model

I can see that [pwiz](https://github.com/coleifer/peewee/blob/da9b941890e9439dd3c20237d51c3dd25b9bb845/pwiz.py#L95) this is where the primary key is being skipped but I don't know why.

---

There is another problem here which is not actually related to pwiz, but something that I am running into. 
This is an old app which was initially written in PHP and I am migrating the API's to python and some column names are reserved words in python like ```type``` and ```list```. What I would like to know that if there is a way in pwiz where I can specify column name substitution.


Peewee uses a convention of implicitly assigning an auto-incrementing integer primary key named "id" (in the absence of the user explicitly declaring a column as the primary key). Since your table follows this convention, there is no need to explicitly declare the id field.