如何使用mysql实现关系数据库(How to implement relational database using mysql)
我在mysql数据库中创建了2个表。 我用了以下代码。
CREATE TABLE Country ( CountryID VARCHAR(8) PRIMARY KEY, CountryName VARCHAR(15) UNIQUE NOT NULL )ENGINE=INNODB; CREATE TABLE Agent ( AgentNo VARCHAR(10) PRIMARY KEY, AgentName VARCHAR(50) UNIQUE NOT NULL, AddNo VARCHAR(8) NOT NULL, Street VARCHAR(25) NOT NULL, City VARCHAR(20) NOT NULL, ContactPerson VARCHAR(20), Email VARCHAR(40), CountryID VARCHAR(8) NOT NULL REFERENCES Country(CountryID) )ENGINE=INNODB;
但是当我尝试删除Country表时,它允许删除该表。 但代理表仍在数据库中。
我认为这些表之间没有正确实现外键引用。 我怎么解决这个问题。
我不熟悉mysql。 我熟悉MS SQL Server,我没有遇到过类似的问题。
I created 2 tables inside mysql database. i used following codes for that.
CREATE TABLE Country ( CountryID VARCHAR(8) PRIMARY KEY, CountryName VARCHAR(15) UNIQUE NOT NULL )ENGINE=INNODB; CREATE TABLE Agent ( AgentNo VARCHAR(10) PRIMARY KEY, AgentName VARCHAR(50) UNIQUE NOT NULL, AddNo VARCHAR(8) NOT NULL, Street VARCHAR(25) NOT NULL, City VARCHAR(20) NOT NULL, ContactPerson VARCHAR(20), Email VARCHAR(40), CountryID VARCHAR(8) NOT NULL REFERENCES Country(CountryID) )ENGINE=INNODB;
But when i try to drop Country table it allow to drop that table. but Agent table still in the database.
I think foreign key reference does not properly implemented between these table. How can i solve this problem.
I am not familiar with mysql. I have familiar with MS SQL Server and i did not face problem like that before.
原文:https://stackoverflow.com/questions/14032488
最满意答案
好的,首先解决方法是在
attr
上使用update
功能。 看看这个旋风 。我用
this.set('name', 'tom')
和this.attrs.name.update('tom')
带有{{attrs.name}}
{{name}}
替换了this.set('name', 'tom')
。解决方法的另一种方法就是在Ember.run.later中包装asignment,就像我在这里完成的那样,我用
this.set('name', 'tom')
替换了this.set('name', 'tom')
:Ember.run.later(() => { this.set('name', 'tom'); });
这就是解决方法。
绑定未在init上完全设置的事实有很长的历史。 但通常它是一个反模式来初始化子组件中的值并将该值提供给父组件。 它使您的代码可读性降低,并且再次成为DDAU (Data down,Actions up)原则。
我建议在创建模型时显式初始化数据,而不是在组件评估周期中隐式显示。
对于您不想存储的默认值,我建议您编写计算属性:
nameWithDefault: computed('name', { get() { return get(this, 'name') || 'tom'; }, set(key, val) { set(this, 'name', val); } })
这是显式的,不会在查看组件后写下数据,并且适用于用户。
Okay, first a way to work around is to use the
update
function on theattr
. Checkout this twiddle.I replaced
this.set('name', 'tom')
withthis.attrs.name.update('tom')
in the.js
and{{name}}
with{{attrs.name}}
in the.hbs
.Another way to work around is just to wrap the asignment in a
Ember.run.later
like I've done here, where I replacedthis.set('name', 'tom')
with that:Ember.run.later(() => { this.set('name', 'tom'); });
So that are the workarounds.
The fact that the bindings are not completely set up on init has a long history. But generally its an anti pattern to initialize a value in a child component and give this value up to the parent. It makes your code less readable and is agains the DDAU (Data down, Actions up) principle.
I recommend to initialize the data explicit when you create your models, not implicit during your component evaluation cycle.
For default values that you don't want to store I recommend you to write a computed property:
nameWithDefault: computed('name', { get() { return get(this, 'name') || 'tom'; }, set(key, val) { set(this, 'name', val); } })
This is explicit, does not write down the data after a component is viewed, and works for the user.
相关问答
更多-
你在谈论只读功能吗? 您无法使用键映射覆盖它。 没有“只读”键映射捕获所有键击并发出错误。 要覆盖read-only-mode ,只需关闭read-only-mode ! 在代码中,设置buffer-read-only变量。 您还可以在代码中绑定inhibit-read-only变量以忽略所有只读机制(包括文本特定区域的属性 - 请参阅下面列表中的级别7和3)。 除了只读之外,其他键映射完全可以优先于您的次模式映射,但我倾向于说,对于与次模式键映射的任何罕见冲突,您应该直接修改与您的冲突相对应的键映射拥有。 ...
-
如果google.maps.places.Autocomplete需要一个DOM元素,那么您必须将此。$()传递给它。 我认为你已经在didInsertElement钩子中做到了这一点。 就像是: App.AutoCompleAddressView = Ember.TextField.extend({ type: 'text', didInsertElement: function() { var options = { types: ['(cities)'], co ...
-
在init的值赋值后,emberjs双向绑定暂时中断(emberjs two-way-binding temporarily broken after value assignment at init)[2022-06-04]
好的,首先解决方法是在attr上使用update功能。 看看这个旋风 。 我用this.set('name', 'tom')和this.attrs.name.update('tom')带有{{attrs.name}} {{name}}替换了this.set('name', 'tom') 。 解决方法的另一种方法就是在Ember.run.later中包装asignment,就像我在这里完成的那样,我用this.set('name', 'tom')替换了this.set('name', 'tom') : Emb ... -
Dropzone:绑定到init(Dropzone: Binding to init)[2022-06-06]
init函数可以直接绑定到新的Dropzone实例: if $('.js-listing__images-upload').length imageUpload = new Dropzone( '.js-listing__images-upload', addRemoveLinks: true maxFiles: 5 maxFilesize: 3 acceptedFiles: 'image/jpeg,image/png,image/gif' init: - ... -
您可能从外角度范围调用showSchedules()函数。 你需要通过将函数体包装在$scope.$apply(...)来告诉angular更新绑定$scope.$apply(...) : $scope.schedule = {}; $scope.showSchedules = function(schedule) { $scope.$apply( $scope.schedule = schedule; ); } 您可以在$scope.$apply(...)调用中包含对sh ...
-
不要将ng-model直接绑定到基本类型,而是使用对象: $scope.sum = { ofCheckValues: 3 }; 在HTML上: ng-model="sum.ofCheckValues" “无论什么时候你都有模型,那里必须有一个点。 如果你没有一个圆点,你做错了。“ plunker : http : //plnkr.co/edit/NRAk3kyP1rdDmYrsz6ZL?p = preview Don't bind the ng-model directly to primitive ...
-
一个好的编译器会隐藏副本并构造一个单独的向量。 在禁用此优化的情况下,发生的情况取决于您是否使用C ++ 11支持进行编译。 我特别关注这一行,缺乏作为类成员的上下文(因为非静态成员初始化器是C ++ 11的一个特性): std::vector
buf = std::vector (BUF_SIZE); 在C ++ 11之前,将构建一个向量(临时),然后buf将从此临时对象复制构建,然后临时对象被销毁。 如果矢量很大,这确实是非常低效的。 从C ++ 11开始,构造临时对象,然后b ... -
绑定与分配(Binding vs Assignment)[2022-10-04]
我以前听过这个解释,看起来很不错: 您可以将绑定视为行李箱上的标签,并将其指定为行李箱。 在其他语言中,您有分配,更像是在手提箱中放置一个值。 实际上,您可以更改行李箱中的值并输入不同的值。 如果你有一个有价值的手提箱,在Elixir ,你在上面放了一个标签。 您可以更改标签,但行李箱中的值仍然相同。 所以,举例来说: iex(1)> x = 1 iex(2)> f = fn -> x end iex(3)> x = 2 iex(4)> f.() 1 你有一个装有1的手提箱,你将它标记为x 。 然后你说, ... -
在设置DependencyProperty值时, DependencyObject检查新值是否为BindingExpression 。 如果不是,则检查先前的值是否为绑定表达式。 对于先前的绑定表达式,它尝试设置表达式的值。 尝试设置值时BindingExpression检查模式,对于OneWay,它返回false而不设置值,并取消激活并分离依赖项属性的绑定表达式。 因此,对于Mode=OnWay ,绑定将针对依赖项属性进行停用和分离。 对于TwoWay ,由于BindingExpression能够设置值, ...
-
在__init__()中定义它的优点是你知道在任何其他方法之前都会被调用,因此你可以避免在创建它之前尝试访问它的风险。 例如,比较在__init__()创建成员变量的代码: #!/usr/bin/env python class human(object): def __init__(self): self.name = '
' def nameBaby(self, name): self.name = name def ...