# Mobile Database with foreign key

**URL:** <https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769>\
**Category:** ionic-v1\
**Created:** [December 8, 2014, 1:01pm UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769 "2014-12-08T13:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabhgupta050](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/saurabhgupta050/32/6996_2.png) [@saurabhgupta050](https://forum.ionicframework.com/u/saurabhgupta050)\
**Post date:** [December 8, 2014, 1:01pm UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769/1 "2014-12-08T13:01:00Z")

</div>

Hi, I an using Sqlite plugin for databases. But I am having trouble creating foreign keys. I followed the syntax of creating foreign keys while creating tables but foreign key constraints are not working. I also tried PRAGMA foreign = ON; on database but it has no impact. Can anyone guide me how to enforce foreign key constraints in Ionic apps.

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [February 25, 2016, 10:35am UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769/2 "2016-02-25T10:35:48Z")

</div>

same here where you able to figure it out:fearful:

---

<div class="post-metadata">

**Author:** ![coreelements](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@coreelements](https://forum.ionicframework.com/u/coreelements)\
**Post date:** [February 25, 2016, 10:42am UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769/3 "2016-02-25T10:42:42Z")

</div>

wich sqllite version does the plugin use?

[https://www.sqlite.org/foreignkeys.html](https://www.sqlite.org/foreignkeys.html)

> This document describes the support for SQL foreign key constraints  
> introduced in SQLite version 3.6.19.

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [February 25, 2016, 10:50am UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769/4 "2016-02-25T10:50:07Z")

</div>

i dont Know That but if i run this code then it throws error  
$cordovaSQLite.execute(db,“PRAGMA foreign\_keys= ON”).then(function(res) {  
console.log(res);  
}, function(err) {  
console.error(err);  
});

could not prepare statement (23 not authorized)

---

<div class="post-metadata">

**Author:** ![coreelements](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@coreelements](https://forum.ionicframework.com/u/coreelements)\
**Post date:** [February 25, 2016, 11:45am UTC](https://forum.ionicframework.com/t/mobile-database-with-foreign-key/13769/5 "2016-02-25T11:45:33Z")

</div>

maybe this helps?

> <https://stackoverflow.com/questions/2421189/version-of-sqlite-used-in-android>
