Create Django models for the User entities that reflect the provided database schema. Ensure all fields and relationships are accurately represented within the Django ORM.
Task Description:
Define the User Model
Action: In your users app (create one if it doesn't exist), define a User model in models.py with all the fields as specified in the schema: user_id, first_name, last_name, email, password, user_phone, title, and role.
Fields:
Use models.AutoField for user_id with primary_key=True.
Use models.CharField for string-based fields.
Add email uniqueness constraint using unique=True.
Consider using models.IntegerField or models.PositiveSmallIntegerField for the role field.
Considerations:
Field Types: Carefully choose the correct Django field type for each column based on the data type indicated in the schema.
Relationships: Pay special attention to the foreign key relationships, ensuring on_delete behavior is set according to the desired data integrity rules.
Validation: Add appropriate validators to fields where necessary (e.g., email fields).
Migrations: After defining the models, generate and apply migrations using Django's makemigrations and migrate commands.
Deliverables:
A models.py file in each app (users) with the defined models.
A successful creation of corresponding tables in the database after migration.
Define Django Models for Users
Create Django models for the
User
entities that reflect the provided database schema. Ensure all fields and relationships are accurately represented within the Django ORM.Task Description:
users
app (create one if it doesn't exist), define aUser
model inmodels.py
with all the fields as specified in the schema:user_id
,first_name
,last_name
,email
,password
,user_phone
,title
, androle
.models.AutoField
foruser_id
withprimary_key=True
.models.CharField
for string-based fields.unique=True
.models.IntegerField
ormodels.PositiveSmallIntegerField
for therole
field.Considerations:
on_delete
behavior is set according to the desired data integrity rules.makemigrations
andmigrate
commands.Deliverables:
models.py
file in each app (users
) with the defined models.