Reputation: 851
Git Repository Request to guide me on what to do.
I work on an e-commerce website with the help of Django. and I'm a beginner in Django The following image provides a table of my database. It helps to add a product
Shows me an error in the browser. This error shows me when I add a product inside the admin panel. It helps to add a product but when I add the product the following error occurs.
An error occurred while migrating
Request to guide me on what to do.
Upvotes: 4
Views: 9428
Reputation: 1847
Take a look at here (Django Migrations Workflow)
I've seen your migrations folder on your Github repo and there was no sign of any of the fields you mentioned.
Every time you add fields to your models, you need to run following commands in terminal
python manage.py makemigrations <app name>
python manage.py migrate
These commands are going to modify your tables.
Please markdown your question instead of putting a picture from your code. Check this out: How do I ask a good question?
EDIT:
In your Product model, there is a field named desc
. You need to set a default value for it; Otherwise, you need to update the records in your database manually.
desc = models.CharField(max_length=300, default='')
After you do that, this error will happen to the pub_date
field too. So, if your current Product objects in your database are not important, you can simply delete the database file db.sqlite3
and delete your migrations file from this address shop/migrations/0001_initial.py
and try the migration commands again.
Upvotes: 1
Reputation: 2627
After first migrations,if you add any field that can not be null you must provide a default value. Your desc field is not nullable, so you must add default='some_value'
inside your desc field.
Upvotes: 5
Reputation: 140
Do you have the table ready and set up? Because the error says, that there is a table named shop_product, but it does not have a column named product_name.
So the structure of your table would get us closer to the solution of your problem.
Edit:
I have just seen, that you supplied your Git repo. I looked at the database and what I wrote above holds true. Your shop_product table has no columns. I did not look through your code to see if it would be set up automatically, but I suppose you were supposed to create the columns by hand, right?
Upvotes: 0