column names are stripped their '_id' part
See original GitHub issueIt seems that when a column is named, say “table_id”, the generated models is always “table”.
Command used: python -m pwiz -e mysql -u root database >> models.py
edit: I observe the same behavior with names such as “app-id”
e.g.:
sql schema:
DROP TABLE IF EXISTS Application
;
/!40101 SET @saved_cs_client = @@character_set_client */;
/!40101 SET character_set_client = utf8 /;
CREATE TABLE Application
(
id
int(11) NOT NULL AUTO_INCREMENT,
app_id
char(100) NOT NULL,
app_name
char(100) NOT NULL,
app_env
text,
app_submit
text NOT NULL,
app_dag
text,
app_master
char(100) NOT NULL,
app_driver
int(11) DEFAULT NULL,
PRIMARY KEY (id
),
KEY app_driver
(app_driver
),
CONSTRAINT Application_ibfk_1
FOREIGN KEY (app_driver
) REFERENCES Container
(id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/!40101 SET character_set_client = @saved_cs_client */;
class Application(BaseModel): app_dag = TextField(null=True) app_driver = ForeignKeyField(db_column=‘app_driver’, null=True, rel_model=Container, to_field=‘id’) app_env = TextField(null=True) app = CharField(db_column=‘app_id’) app_master = CharField() app_name = CharField() app_submit = TextField()
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Is there any way to keep “_id” exist?
You can name your fields whatever you want, just specify the actual column name using the
column_name
parameter: