Friday, December 26, 2014

Re: initial dta for model in Django 1.7 or newer

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



 

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, смотреть документацию, иначе выдаст варианты. 


--
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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/22ddfde1-540d-466b-bb1b-6b814ed057ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment