[Answer]-Django – Creating Objects for models and saving it to MYSQL

1👍

You’ve made a few errors in defining your model.

First, there is no reason to define your fields IN UPPER CASE. That’s very strange.

More importantly, you have defined a USER_ID field as a charfield and set it to be the primary key. But you have not provided any way to actually generate a new value for this field. Unless you have a really good reason, you should not define a manual PK field at all, but let Django add an autoincremented integer field automatically.

But even more importantly than this, you should on no account do what you have done here at all. You are storing your passwords in clear text in the database, opening yourself to all sorts of hacking. Do not ever do this. Django includes a whole authentication framework where this is done properly, and there is absolutely no reason for you to bypass this as you have done. Do not do it.

Leave a comment