In Django series part 1 - Generating dummy data, I’m getting an error in datagrip(Refer to the image). I downloaded the database from mockaroo as instructed in the video, but when I run the MySQL database, it reports errors.
Although there are no email, phone, or membership fields in the database, it generates errors after running in the storefront schema.
Can anyone please help me?
Did you make sure to set up the Mockeroo fields like mosh did like before downloading? Like adding membership field and changing gender to phone etc.
Because your SQL insert statements there are only inserting id, first_name and last_name into your table, not the other fields like email, phone, membership etc
Thank you for responding. I’m a newbie who has only recently begun the Django series.
I followed the video and made the setup in the Mockeroo fields the same as mosh. It returned an error of “ Data truncated for column ‘phone’ at row 1”. Please let me know where I’m going wrong.
Hi I had this error too, the error is because the dummy data is too large to fit inside the defined length for that column, its likely because some settings has changed with the software since the time of the video or something.
The best thing is just to continue on with the course because this sections ends just here then Mosh makes sure that we are on the same page on the ‘Resetting the Database’ lecture, he tells you to drag and drop a sql file into datagrip and some django files into vscode, so then everyone has the same data and can continue with the course
Thanks for clearing up my doubt. I will move on with the course.
I continued with the course and after resetting the data and after uploading the seed file in datagrip it show me an error again - "Duplicate Entry ‘2’ for key ‘sstore_collection.PRIMARY’. Please help me.
This error means that there is already data in the table you are trying to update, be sure to make sure the database is fresh and clean from any other data before dropping in the files
I am sure the database is fresh but I don’t know why this error shows up every time. I tried in different ways but it didn’t work.
try deleting the storefront database and recreating from scratch as Mosh does in the “resetting the database” video
After watching the resetting database I tried it twice but the same error pops up. Even I tried deleting the localhost but the same error.
Can you write out step-by-step how you’re resetting the database?
- Dragged and dropped storefront folder from resources in VS code
- Changed password in settings.py → Database
- Run pipenv install in cmd
- Deleted database storefront in datagrip
- Created New database storefront in localhost
- Activated virtual environment - pipenv shell
- Run python manage.py migrate
- Refreshed data in datagrip
- Closed all sessions
- Dragged and dropped seed.sql file from data in resources
- Selected schema - storefront. Selected all and executed them all.
Then it shows me an error of Data truncation: Data too long for column ‘title’ at row 3
Hmm, well it looks like you’re doing everything correctly…I went back and watched the lesson over again and made notes:
Go to zip file that Mosh gave us at the beginning of the course, called Resources.
Navigate to Code/5- Django ORM/Start/storefront
Drag and drop the storefront folder into VS Code. You could also save that folder where you prefer and open it in VS Code.
In storefront/settings.py , change the DATABASES “PASSWORD” from ‘MyPassword’ to your SQL password.
Open a terminal window in VS Code and run ‘pipenv install’.
Open DataGrip or whatever you’re using.
Delete the storefront database by right clicking on it and going down to Drop. Click on it, and click delete on the popup window.
Right click on ‘@localhost’ and open a new query console.
Type into the query console ‘CREATE DATABASE storefront’.
Verify that a new database was created in the dropdown list. It should be empty and have no subfolders.
Back in VS Code, in the terminal run ‘pipenv shell’ to activate the virtual environment.
Then, in the terminal, run ‘ python manage.py migrate’. You should see “Applying to store…” many times.
Back in DataGrip, hit refresh, and all of the storefront tables should have been created. They are still empty of data.
Before continuing, close all sessions of DataGrip. Go to the bottom of DataGrip and on the Services tab, right click on @localhost and “Close All Sessions”.
Right click on storefront and open a new query console.
From the Resources folder that Mosh gave us, navigate to Data/seed.sql. Drag and drop that seed.sql file into the new query console you created in DataGrip. You should see a giant list fill the query console.
On the top select schema, and choose storefront. For me, DataGrip doesn’t always choose @localhost by default, so I sometimes have to select it from the dropdown menu to the right of schema.
So now select all the data in the query console (Ctrl + a or Cmd + a).
Execute it all with the green play triangle (or Ctrl + Shift + Return).
Hopefully at this point your tables populate!
Perhaps the Resources folder that you downloaded from Mosh was corrupted in some way, so the seed.sql file is bad. Maybe delete it and re-download, and give it another run?