Home > Software engineering >  how to insert list of data into django database?
how to insert list of data into django database?

Time:01-02

I made a list of items in string that i wanted to insert them into my Country table from shell, well wasn't successful so need some help.(i tried to add it as list and tuple but didn't work just caused more errors) I use sqlite3 database models.py

class Country(models.Model):
    #countries list
    country_name = models.CharField(max_length=100)

a list like this 'Afghanistan', 'Albania', 'Algeria', 'Andorra'

CodePudding user response:

This should do it:

for s in your_list: Country.objects.create(country_name= s)
  • Related