initial dta for model in Django 1.7 or newer

29 views
Skip to first unread message

Robert Jonathan Šimon

unread,
Dec 25, 2014, 10:06:35 AM12/25/14
to django...@googlegroups.com
Hi,
When i googled for this problem a found out, that with migrations in Django 1.7, there is new way how it should be done, but i didnt understand it how. Can anyone explain me the new way how to do it?
Thanks a lot.

Валерий Бовсуновский

unread,
Dec 26, 2014, 8:28:00 AM12/26/14
to django...@googlegroups.com


четверг, 25 декабря 2014 г., 18:06:35 UTC+3 пользователь Robert Jonathan Šimon написал:
Hi,
When i googled for this problem a found out, that with migrations in Django 1.7, there is new way how it should be done, but i didnt understand it how. Can anyone explain me the new way how to do it?
Thanks a lot.


python2.7 manage.py makemigrations
python2.7 manage.py migrate 


makemigrations - проверяет есть ли новые таблицы
migrate - создает таблицы или удаляет

Напишите модель простую что бы протестировать

class Home(models.Model):
title = models.CharField(max_length=150)
text = models.TextField(blank=True, null=True)
date = models.DateTimeField(blank=True, null=True)
def __unicode__(self):
return self.title


проведите две  команды


python2.7 manage.py makemigrations
python2.7 manage.py migrate 



Потом закомментируйте одну строку


class Home(models.Model):
title = models.CharField(max_length=150)
#text = models.TextField(blank=True, null=True)
date = models.DateTimeField(blank=True, null=True)
def __unicode__(self):
return self.title


И опять две команды
python2.7 manage.py makemigrations
python2.7 manage.py migrate 

поле удалится
 #text = models.TextField(blank=True, null=True)

Что бы не было ошибок нужно всегда заполнять blank=True, null=True, смотреть документацию, иначе выдаст варианты. 

Robert Jonathan Šimon

unread,
Dec 26, 2014, 9:43:45 AM12/26/14
to django...@googlegroups.com

Hi,
I am very sorry, but I don't understand russian. Can you answer me in english? And I am using Python 3.4.

Dne 26. 12. 2014 14:30 "Валерий Бовсуновский" <id29...@gmail.com> napsal(a):
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/9i7Cf5ksaeE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dbd118f7-2410-4755-958f-c1e63f33ad56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Валерий Бовсуновский

unread,
Dec 26, 2014, 10:24:38 AM12/26/14
to django...@googlegroups.com
Here is a good tutorial in English







Hi,
I am very sorry, but I don't understand russian. Can you answer me in english? And I am using Python 3.4.

Dne 26. 12. 2014 14:30 "Валерий Бовсуновский" <id29...@gmail.com> napsal(a):


четверг, 25 декабря 2014 г., 18:06:35 UTC+3 пользователь Robert Jonathan Šimon написал:
Hi,
When i googled for this problem a found out, that with migrations in Django 1.7, there is new way how it should be done, but i didnt understand it how. Can anyone explain me the new way how to do it?
Thanks a lot.


python2.7 manage.py makemigrations
python2.7 manage.py migrate 

Delete table

Collin Anderson

unread,
Dec 29, 2014, 12:41:03 AM12/29/14
to django...@googlegroups.com
Hi,

You are asking about initial data? Use RunPython or RunSQL.

Collin
Reply all
Reply to author
Forward
0 new messages