mysql - 想要向现有表添加一个外键列

标签 mysql django foreign-keys models

在我的 Django 应用程序 models.py 中,我最近添加了这个字段。

 Class Client
     user  = models.ForeignKey(User)

我想在 mysql 中将这个字段添加到一个现有表。问题是我不知道处理外键的命令。我要添加此列的表的名称称为 tiptop_clients

最佳答案

您可以使用 sqldiff -命令django-extensions :

Django command that scans all models for the given appnames and compares there database schema with the real database tables.

It indicates how columns in the database are different from the SQL that would be generated by Django. This command is not a database migration tool. Though it might certainly be of help during migrations. It’s purpose is to show the current differences as a way to checking or debugging your models compared to the real database tables and columns.

关于mysql - 想要向现有表添加一个外键列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569562/

相关文章:

python - 如何使用 mysql 表中的信息创建条形图?

php - 当服务器的使用量超过限制时将用户重定向到静态页面

mysql - 通过 mySQL 触发器将行插入另一个表

php - 具有多个自定义字段的 wp_query 返回 0 个结果

Django:将其转换为 DetailView - 使用 URL 中的两个参数的 View 函数

django - 在 Django 中获取 QuerySet 的值

python - GeoDjango GEOSException 错误

mysql - rails 4.2 : Turn a reference field into foreign key

c# - Entity Framework .net : "The Name value should be a valid navigation property name."

mysql - 无法从空表中截断外键约束中引用的表