为什么我们不能使用自己的mysql数据库而不是django数据库?

时间:2022-06-11 16:56:31

I have already created a mysql database with the tables table1,table2,table3. I have configured my database details in settings.py file. I jus want to insert the value into table1. I have created a model.py file look like this.

我已经用表表表1、表2、表3创建了一个mysql数据库。我已经在设置中配置了数据库细节。py文件。我想要将值插入到表1中。我创建了一个模型。py文件是这样的。

model.py

model.py

from django.db import models

class table1(models.Model):
   name = models.CharField(max_length=50)
   phone = models.CharField(max_length=20)
   email = models.CharField(max_length=50)
   password = models.CharField(max_length=50)

Now i want to insert the value of the field name,phone,email,password which is in the tablename table1. when i run the project, it created the new table with the name of myapp_table1 and inserted the value instead of existing table which i create myself before. But i want to insert those value into already existing table table1. Can anyone explain this concept.

现在我要插入表1中的字段名、电话、电子邮件、密码的值。当我运行这个项目时,它用myapp_table1的名称创建了新表,并插入了值,而不是我以前创建的现有表。但我想将这些值插入到已有的表表表1中。有人能解释一下这个概念吗?

1 个解决方案

#1


1  

Django will automatically create your database tables with names {app_name}_{model_name}. If you want to use a different database then you may use the db_name Meta option: https://docs.djangoproject.com/en/dev/ref/models/options/#db-table

Django将自动创建名称为{app_name}_{model_name}的数据库表。如果您想使用不同的数据库,那么您可以使用db_name元选项:https://docs.djangoproject.com/en/dev/ref/models/options/#db-table

Please don't forget that your db tables also need a Primary Key -- django automatically creates one when it creates the tables

请不要忘记,您的db表还需要一个主键——django在创建表时自动创建一个主键

#1


1  

Django will automatically create your database tables with names {app_name}_{model_name}. If you want to use a different database then you may use the db_name Meta option: https://docs.djangoproject.com/en/dev/ref/models/options/#db-table

Django将自动创建名称为{app_name}_{model_name}的数据库表。如果您想使用不同的数据库,那么您可以使用db_name元选项:https://docs.djangoproject.com/en/dev/ref/models/options/#db-table

Please don't forget that your db tables also need a Primary Key -- django automatically creates one when it creates the tables

请不要忘记,您的db表还需要一个主键——django在创建表时自动创建一个主键