我正在尝试将我的新架构转发到我的数据库服务器上,但我无法弄清楚为什么我收到此错误.我试图在这里搜索答案,但我发现的所有内容都说要么将数据库引擎设置为Innodb,要么确保我尝试用作外键的密钥是他们自己的表中的主键.如果我没弄错的话,我已经完成了这两件事.你们可以提供的任何其他帮助?
Executing SQL script in server
ERROR: Error 1215: Cannot add foreign key constraint
-- -----------------------------------------------------
-- Table `Alternative_Pathways`.`Clients_has_Staff`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Alternative_Pathways`.`Clients_has_Staff` (
`Clients_Case_Number` INT NOT NULL ,
`Staff_Emp_ID` INT NOT NULL ,
PRIMARY KEY (`Clients_Case_Number`, `Staff_Emp_ID`) ,
INDEX `fk_Clients_has_Staff_Staff1_idx` (`Staff_Emp_ID` ASC) ,
INDEX `fk_Clients_has_Staff_Clients_idx` (`Clients_Case_Number` ASC) ,
CONSTRAINT `fk_Clients_has_Staff_Clients`
FOREIGN KEY (`Clients_Case_Number` )
REFERENCES `Alternative_Pathways`.`Clients` (`Case_Number` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Clients_has_Staff_Staff1`
FOREIGN KEY (`Staff_Emp_ID` )
REFERENCES `Alternative_Pathways`.`Staff` (`Emp_ID` …Run Code Online (Sandbox Code Playgroud) 数据库latin1_general_ci现在,我想将排序更改为utf8mb4_general_ci.
PhpMyAdmin中是否有任何设置可以更改数据库,表,列的排序规则?而不是一个一个地改变?
我读过数据库系统概念,第6版,Silberschatz.我将在MySQL的OS X上实现第2章中所示的大学数据库系统.但是我在创建表时遇到了麻烦course.表格department看起来像
mysql> select * from department
-> ;
+------------+----------+-----------+
| dept_name | building | budget |
+------------+----------+-----------+
| Biology | Watson | 90000.00 |
| Comp. Sci. | Taylor | 100000.00 |
| Elec. Eng. | Taylor | 85000.00 |
| Finance | Painter | 120000.00 |
| History | Painter | 50000.00 |
| Music | Packard | 80000.00 |
| Physics | Watson | 70000.00 |
+------------+----------+-----------+
mysql> show …Run Code Online (Sandbox Code Playgroud) 我正在使用MySQL DB构建一个django应用程序.当我第一次运行'python manage.py migrate'时,会创建一些表,然后会出现一些错误.带来的错误是:
django.db.utils.IntegrityError:(1215,'无法添加外键约束')
当我运行这个MySQL命令时 -
SHOW ENGINE INNODB状态\ G,
我明白了>>>
2015-02-17 14:33:17 7f10891cf700 Error in foreign key constraint of table movie_store/#sql-4f1_66:
FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`):
Cannot resolve table name close to:
(`id`)
Run Code Online (Sandbox Code Playgroud)
完整的追溯是:
Creating tables...
Creating table users
Creating table merchant
Creating table celery_taskmeta
Creating table celery_tasksetmeta
Creating table djcelery_intervalschedule
Creating table djcelery_crontabschedule
Creating table djcelery_periodictasks
Creating table djcelery_periodictask
Creating table djcelery_workerstate
Creating table djcelery_taskstate
Creating table post_office_email
Creating table post_office_log
Creating table post_office_emailtemplate
Creating table …Run Code Online (Sandbox Code Playgroud) 我试图创建一个外键使用artisan,但这个错误出现了.
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `comments` add constraint `comments_comment_lot_id_foreign` foreign key (`comment_lot_id`) references `lots` (`lot_id`
) on delete cascade)
Run Code Online (Sandbox Code Playgroud)
这是我的迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->text('comment');
$table->integer('comment_lot_id')->unsigned();
$table->timestamps();
});
Schema::table('comments', function ($table) {
$table->foreign('comment_lot_id')->references('lot_id')->on('lots')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
* …Run Code Online (Sandbox Code Playgroud) 当引用的表实际上是视图时,我可以在MYSQL中添加外键约束吗?
基于以下我可能想知道一个表和一个视图被认为是不同的格式/sf/answers/2182838521/
在我看来这是不允许的,但我没有看到任何实际上说它被禁止的东西.
新的迁移(添加一个简单的表)在迁移过程中给出错误“无法添加外键约束”。
这是一个现有的模型,称为EventLog:
class EventLog(models.Model):
"""
The event log.
"""
user = models.ForeignKey(User, blank=True, null=True)
timestamp = models.DateTimeField(auto_now=True)
text = models.TextField(blank=True, null=True)
ip = models.CharField(max_length=15)
metadata = JSONField(default={},blank=True)
product = models.TextField(default=None,blank=True, null=True)
type = models.ForeignKey(EventType)
def __unicode__(self):
return "[%-15s]-[%s] %s (%s)" % (self.type, self.timestamp, self.text, self.user)
def highlite(self):
if self.type.highlite:
return self.type.highlitecss
return False
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试创建的新模型:
class EventLogDetail(models.Model):
# NOTE: I've already tried switching 'EventLog' out for just EventLog.
eventlog = models.ForeignKey('EventLog', related_name='details')
order = models.IntegerField(default=0)
line = models.CharField(max_length=500)
class …Run Code Online (Sandbox Code Playgroud) 当我尝试在Laravel 5中通过迁移设置外键约束时,收到错误消息:
[Illuminate \ Database \ QueryException] SQLSTATE [HY000]:常规错误:1215无法添加外键约束(SQL:在删除级联上,alter table
rittenregistratie添加合作rittenregistratie_karakterrit_id_foreign外键(karakterrit_id)引用karakterrit(id))[PDOException] SQLSTATE [HY000]:常规错误:1215无法添加外键约束D:\ wamp \ www>
但是我现在知道为什么了吗???迁移顺序正确,为什么我会收到此错误?表rittenregistratie具有一个名为karakterrit_id的外键,这是表karakterrit中的主键。
这是我的迁移rittenregistratie:
public function up()
{
Schema::create('rittenregistratie', function (Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->timestamps('datum');
$table->integer('beginstand');
$table->integer('eindstand');
$table->text('van');
$table->text('naar');
$table->text('bezoekadres');
$table->text('geredenroute');
$table->integer('karakterrit_id')->default(1);
$table->text('toelichting');
$table->integer('kilometerszakelijk');
$table->integer('kilomteresprive');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->foreign('karakterrit_id')
->references('id')
->on('karakterrit')
->onDelete('cascade');
});
}
Run Code Online (Sandbox Code Playgroud)