首页 \ 问答 \ 如何使用mysql实现关系数据库(How to implement relational database using mysql)

如何使用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
更新时间:2022-05-23 17:05

最满意答案

好的,首先解决方法是在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 the attr. Checkout this twiddle.

I replaced this.set('name', 'tom') with this.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 replaced this.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 ...
  • 好的,首先解决方法是在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 ...
  • 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 ...
  • 我以前听过这个解释,看起来很不错: 您可以将绑定视为行李箱上的标签,并将其指定为行李箱。 在其他语言中,您有分配,更像是在手提箱中放置一个值。 实际上,您可以更改行李箱中的值并输入不同的值。 如果你有一个有价值的手提箱,在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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)