在 Django 中创建和迁移模型后如何在我的数据库中查看 table
how to see the table in my database after creating and migrating models in django
我尝试用 visual studio 代码连接到我的 sql 云集群
settings.py 的代码是-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME':'aras',
'USER':'arasuser',
'PASSWORD':'**********',
'HOST':'mysql-numbers-0.cloudclusters.net',
'connection':'connect1',
}
}
后来,我创建了一个模型和 运行 迁移。但是我无法在我的数据库中看到 table。
我连接对了吗?
已更新
models.py代码
from django.db import models
# Create your models here.
class category(models.Model):
category_id = models.AutoField(primary_key=True)
category_name=models.CharField(max_length=500)
def __str__(self):
return self.category_name
您可以在DB Browser for SQLite
中安装并登录:https://sqlitebrowser.org/
完成这个 link。
python sqlite use in terminal -django
models.py
from django.db import models
class Event(models.Model):
name = models.CharField('Event Name', max_length=120)
event_date = models.DateTimeField('Event Date')
venue = models.CharField(max_length=120)
manager = models.CharField(max_length=60)
description = models.TextField(blank=True)
创建模型后
python manage.py makemigrations
终端输出:
Migrations for 'events':
events\migrations[=12=]01_initial.py
- Create model Event
然后
python manage.py migrate
终端输出:
Operations to perform:
Apply all migrations: events
Running migrations:
Applying events.0001_initial... OK
Django 使用模型生成SQL,试试这个命令
python manage.py sqlmigrate events 0001_initial
BEGIN;
--
-- Create model Event
--
CREATE TABLE "events_event" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(120) NOT NULL,
"event_date" datetime NOT NULL,
"venue" varchar(120) NOT NULL,
"manager" varchar(60) NOT NULL,
"description" text NOT NULL
);
COMMIT;
数据库:
python manage.py sqlmigrate 事件 0001_initial
更多信息:https://djangobook.com/mdj2-models/#creating-database-records
我尝试用 visual studio 代码连接到我的 sql 云集群 settings.py 的代码是-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME':'aras',
'USER':'arasuser',
'PASSWORD':'**********',
'HOST':'mysql-numbers-0.cloudclusters.net',
'connection':'connect1',
}
}
后来,我创建了一个模型和 运行 迁移。但是我无法在我的数据库中看到 table。 我连接对了吗?
已更新 models.py代码
from django.db import models
# Create your models here.
class category(models.Model):
category_id = models.AutoField(primary_key=True)
category_name=models.CharField(max_length=500)
def __str__(self):
return self.category_name
您可以在DB Browser for SQLite
中安装并登录:https://sqlitebrowser.org/
完成这个 link。
python sqlite use in terminal -django
models.py
from django.db import models
class Event(models.Model):
name = models.CharField('Event Name', max_length=120)
event_date = models.DateTimeField('Event Date')
venue = models.CharField(max_length=120)
manager = models.CharField(max_length=60)
description = models.TextField(blank=True)
创建模型后
python manage.py makemigrations
终端输出:
Migrations for 'events':
events\migrations[=12=]01_initial.py
- Create model Event
然后
python manage.py migrate
终端输出:
Operations to perform:
Apply all migrations: events
Running migrations:
Applying events.0001_initial... OK
Django 使用模型生成SQL,试试这个命令
python manage.py sqlmigrate events 0001_initial
BEGIN;
--
-- Create model Event
--
CREATE TABLE "events_event" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(120) NOT NULL,
"event_date" datetime NOT NULL,
"venue" varchar(120) NOT NULL,
"manager" varchar(60) NOT NULL,
"description" text NOT NULL
);
COMMIT;
数据库:
python manage.py sqlmigrate 事件 0001_initial
更多信息:https://djangobook.com/mdj2-models/#creating-database-records