程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django

編輯:Python

List of articles

  • 1.Django Modify the name of the table
  • 2.Django Add table content

1.Django Modify the name of the table

# stay Model in
class Meta:
db_table = "new_tablename" # Change table name

2.Django Add table content

1. Directly in models.py add

class User(models.Model):
username=models.CharField(max_length=50)
password=models.CharField(max_length=50)
zhname = models.CharField(max_length=50)

I added the zhname = models.CharField(max_length=50)
And then in turn

1.python manage.py makemigrations
2.python manage.py migrate

Error when executing the first sentence

You are trying to add a non-nullable field 'name' to contact without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:

resolvent : to zhname Give initial value ’abc’

zhname = models.CharField(max_length=50,default='abc')

And then execute one after the other

python manage.py makemigrations
python manage.py migrate

Delete default Default initial value default=‘abc’
Re execution

python manage.py makemigrations
python manage.py migrate

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved