- 论坛徽章:
- 0
|
1. django-admin startproject django_test 2. vim settings.py change the database session. DATABASES = { 'default': { 'ENGINE': 'mysql',#'django.db.backends.', Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'django_test', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite 3. django-admin startapp django_web 4. vim models.py from django.db import models
# Create your models here.
class TestGroup(models.Model): test_group = models.CharField(max_length=100, blank = True) component = models.CharField(max_length=100, blank = True, unique = True)
class Meta: db_table = 'test_group' def __unicode__(self): return self.test_group 5. add 'django_test.django_web' to settings.py 6. ./manage.py validate this will varify the syntax of settings.py and models.py 7. ./manage.py sql django_web show the sql statement from models something like
- BEGIN;CREATE TABLE `test_group` (
-
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
-
`test_group` varchar(100) NOT NULL,
-
`component` varchar(100) NOT NULL UNIQUE
-
)
-
;COMMIT;
8. ./manage.py syncdb create 'test_group' table and other tables under django_test database.
- describe test_group;
-
+------------+--------------+------+-----+---------+----------------+
-
| Field | Type | Null | Key | Default | Extra |
-
+------------+--------------+------+-----+---------+----------------+
-
| id | int(11) | NO | PRI | NULL | auto_increment |
-
| test_group | varchar(100) | NO | | NULL | |
-
| component | varchar(100) | NO | UNI | NULL | |
-
+------------+--------------+------+-----+---------+----------------+
-
3 rows in set (0.00 sec)
|
|