"Cannot add foreign key constraint" when creating test database for tests.
I have a database that works fine, I can interact with it normally through Django. When I try to run unit tests, I use the following command:
python3 manage.py test --settings appname.settings_test
But I get the following error when creating the database:
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
One of my tables does indeed have a foreign key relationship with another, so I'm assuming that the table with the foreign key field is being added before the table that it depends on.
How can I verify that this is the case, and how can I go about addressing this issue so that tables are executed in the correct order?
I've tried a few different fixes, such as re-ordering the apps with each model in the INSTALLED_APPS setting, but nothing I've tried has worked. Any help would be appreciated! I am happy to provide any other information!
EDIT: Full stack trace below. Note that I am deleting the old database at the beginning because I am running this command multiple times in a row, so it's deleting the failed database from my last attempt.
Creating test database for alias 'example'...
Got an error creating the test database: (1007, "Can't create database 'test_example'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_example', or 'no' to cancel: yes
Destroying old test database for alias 'example'...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
/r/django
https://redd.it/8dofs3
I have a database that works fine, I can interact with it normally through Django. When I try to run unit tests, I use the following command:
python3 manage.py test --settings appname.settings_test
But I get the following error when creating the database:
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
One of my tables does indeed have a foreign key relationship with another, so I'm assuming that the table with the foreign key field is being added before the table that it depends on.
How can I verify that this is the case, and how can I go about addressing this issue so that tables are executed in the correct order?
I've tried a few different fixes, such as re-ordering the apps with each model in the INSTALLED_APPS setting, but nothing I've tried has worked. Any help would be appreciated! I am happy to provide any other information!
EDIT: Full stack trace below. Note that I am deleting the old database at the beginning because I am running this command multiple times in a row, so it's deleting the failed database from my last attempt.
Creating test database for alias 'example'...
Got an error creating the test database: (1007, "Can't create database 'test_example'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_example', or 'no' to cancel: yes
Destroying old test database for alias 'example'...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
/r/django
https://redd.it/8dofs3
reddit
"Cannot add foreign key constraint" when creating test... • r/django
I have a database that works fine, I can interact with it normally through Django. When I try to run unit tests, I use the following command: ...
Plot real-time sensor data on a map
I have real-time sensor gps-data (comes from a Kafka consumer) and want to live-track them on a map. Can folium / jupyter-gmaps do that without permanently updating the map in the background? Ideally can I use ipywidgets with those libraries too to build interactive maps?
/r/IPython
https://redd.it/8dozey
I have real-time sensor gps-data (comes from a Kafka consumer) and want to live-track them on a map. Can folium / jupyter-gmaps do that without permanently updating the map in the background? Ideally can I use ipywidgets with those libraries too to build interactive maps?
/r/IPython
https://redd.it/8dozey
reddit
Plot real-time sensor data on a map • r/IPython
I have real-time sensor gps-data (comes from a Kafka consumer) and want to live-track them on a map. Can folium / jupyter-gmaps do that without...
Need help for a RSS feeder app
I'm very new to django and I want to build an RSS and screen-scraping app that will automatically check the feed using crontab and puts the feed in my database. Later I want to show the feed on the website. I know there are few pre build apps like planet but they are outdated and I wanna make it in django 2.0. Am I going in a right direction? Please feel free to leave any suggestion you have
/r/django
https://redd.it/8dn7hv
I'm very new to django and I want to build an RSS and screen-scraping app that will automatically check the feed using crontab and puts the feed in my database. Later I want to show the feed on the website. I know there are few pre build apps like planet but they are outdated and I wanna make it in django 2.0. Am I going in a right direction? Please feel free to leave any suggestion you have
/r/django
https://redd.it/8dn7hv
reddit
Need help for a RSS feeder app • r/django
I'm very new to django and I want to build an RSS and screen-scraping app that will automatically check the feed using crontab and puts the feed...
Validator-Collection / What's your validator wishlist?
Hi Folks!
We just released a [Validator-Collection](https://github.com/insightindustry/validator-collection) library, where v.1.0 supports 60+ of the most common validation approaches we tend to use "in the wild". Here's direct link: https://github.com/insightindustry/validator-collection
We built the collection with the validations that we find ourselves using most often in our projects, so it's got all of the usual suspects (email, URLs, UUID, etc.). But now that we've released v.1.0 of the library, I'm hoping to find out: What kinds of validation do you use most often?
We're thinking of extending the library with image validation (type, size, etc.), configurable password pattern validation, and the like. We'd probably implement them using an extras-requires pattern (that way users of the library who don't want to install heavy image dependencies don't have to).
So I've got two questions for folks:
1. What kinds of validations do you find yourself using most often? What kinds of validations would you find most helpful?
2. Philosophically, how do you feel about a library that uses the extras-require pattern for dependency management?
Meaning, typical installation (no dependencies outside of the standard library, unless on Python 2.7):
pip install validator-collection
(does not include image validation support)
But if you DO want image support, installation using:
pip install validator-collection[images]
Thanks - I look forward to hearing (reading) your thoughts!
(also, FWIW: I'm sensitive to the perennial debate about LBYL and EAFP - philosophically, we've designed the library's API to support both approaches...with luck, we've done a good job balancing between the two).
All the best,
Chris
/r/Python
https://redd.it/8dp4g3
Hi Folks!
We just released a [Validator-Collection](https://github.com/insightindustry/validator-collection) library, where v.1.0 supports 60+ of the most common validation approaches we tend to use "in the wild". Here's direct link: https://github.com/insightindustry/validator-collection
We built the collection with the validations that we find ourselves using most often in our projects, so it's got all of the usual suspects (email, URLs, UUID, etc.). But now that we've released v.1.0 of the library, I'm hoping to find out: What kinds of validation do you use most often?
We're thinking of extending the library with image validation (type, size, etc.), configurable password pattern validation, and the like. We'd probably implement them using an extras-requires pattern (that way users of the library who don't want to install heavy image dependencies don't have to).
So I've got two questions for folks:
1. What kinds of validations do you find yourself using most often? What kinds of validations would you find most helpful?
2. Philosophically, how do you feel about a library that uses the extras-require pattern for dependency management?
Meaning, typical installation (no dependencies outside of the standard library, unless on Python 2.7):
pip install validator-collection
(does not include image validation support)
But if you DO want image support, installation using:
pip install validator-collection[images]
Thanks - I look forward to hearing (reading) your thoughts!
(also, FWIW: I'm sensitive to the perennial debate about LBYL and EAFP - philosophically, we've designed the library's API to support both approaches...with luck, we've done a good job balancing between the two).
All the best,
Chris
/r/Python
https://redd.it/8dp4g3
GitHub
GitHub - insightindustry/validator-collection: Python library of 60+ commonly-used validator functions
Python library of 60+ commonly-used validator functions - GitHub - insightindustry/validator-collection: Python library of 60+ commonly-used validator functions
Flask-YoloAPI 0.1.3 released
I released Flask-YoloAPI version `0.1.3`.
https://github.com/skftn/flask-yoloapi
It allows you to create Flask routes with refined requirements, such as;
- quickly create safe routes by enforcing input/type validation
- coercing of data types
- support for many datatypes
- understands docstrings
- support for python 3.5 type annotations
- custom validation via the `validator=` flag
This library embodies the philosophy of Flask; 'micro web-development'. Quick and easy route creation where you don't need many bells and whistles, yet, you can be very descriptive and strict about what comes into your route.
It is already used in production for the past 6 months under heavy load and works fine. It features a test-suite with 90%+ coverage.
Suggestions welcome, as always.
/r/flask
https://redd.it/8dmgfx
I released Flask-YoloAPI version `0.1.3`.
https://github.com/skftn/flask-yoloapi
It allows you to create Flask routes with refined requirements, such as;
- quickly create safe routes by enforcing input/type validation
- coercing of data types
- support for many datatypes
- understands docstrings
- support for python 3.5 type annotations
- custom validation via the `validator=` flag
This library embodies the philosophy of Flask; 'micro web-development'. Quick and easy route creation where you don't need many bells and whistles, yet, you can be very descriptive and strict about what comes into your route.
It is already used in production for the past 6 months under heavy load and works fine. It features a test-suite with 90%+ coverage.
Suggestions welcome, as always.
/r/flask
https://redd.it/8dmgfx
GitHub
skftn/flask-yoloapi
flask-yoloapi - A small framework for creating simple JSON endpoints.
Simplru - A backport of Python 3 LRU Cache functionality for Python 2
https://github.com/mostafa/simplru
/r/Python
https://redd.it/8dqdim
https://github.com/mostafa/simplru
/r/Python
https://redd.it/8dqdim
GitHub
mostafa/simplru
A backport of Python 3 LRU Cache functionality for Python 2 - mostafa/simplru
I've compiled some unit testing tips, gotchas, etc. Would love some feedback, and I welcome any suggestions or additions.
https://howchoo.com/g/owy4mzvhn2n/unit-testing-in-python-tips-tricks-and-gotchas
/r/Python
https://redd.it/8drs5b
https://howchoo.com/g/owy4mzvhn2n/unit-testing-in-python-tips-tricks-and-gotchas
/r/Python
https://redd.it/8drs5b
howchoo
Unit Testing in Python: Tips, Tricks, and Gotchas
I'll be honest - this guide is primarily a reference for future me. Unit testing is something I want to improve on, and I find myself searching for the same things over and over. So here I will compile a list of tips, tricks, and gotchas - things that will…
Build Your Own Photo Sharing App In 5 minutes With Django and React Native
https://github.com/yasintoy/vecihi
/r/Python
https://redd.it/8dowex
https://github.com/yasintoy/vecihi
/r/Python
https://redd.it/8dowex
GitHub
GitHub - yasintoy/Vecihi: Build Your Own Photo Sharing App in 5 minutes
Build Your Own Photo Sharing App in 5 minutes. Contribute to yasintoy/Vecihi development by creating an account on GitHub.
How to handle JWT authentication in a RESTful API with flask-praetorian (mainly logging users out and handling errors)?
Hi,
I am using [flask\-praetorian](http://flask-praetorian.readthedocs.io/en/latest/index.html), it works fine for logging a user in and protecting a route, but beyond that, I have no idea how to use it to accomplish other tasks like logging out users, handling errors...
For example, accessing a protected route results in the following exception \(with a `500` error instead of a` 40`1 error as it's supposed to\):
flask_praetorian.exceptions.MissingTokenHeader: JWT token not found in headers under 'Authorization' (401)
I am sure other errors \(like an invalid token\) have the same behavior. How can I return a custom message with the proper status code?
Also, I don't know much about JWT, I have read that keeping the user logged in with the same token for an extended period of time is a bad idea, so how can I allow logging out and token expiration? Do you guys have any resources I need to read before making an API with weak security?
Thanks!
/r/flask
https://redd.it/8dqbhl
Hi,
I am using [flask\-praetorian](http://flask-praetorian.readthedocs.io/en/latest/index.html), it works fine for logging a user in and protecting a route, but beyond that, I have no idea how to use it to accomplish other tasks like logging out users, handling errors...
For example, accessing a protected route results in the following exception \(with a `500` error instead of a` 40`1 error as it's supposed to\):
flask_praetorian.exceptions.MissingTokenHeader: JWT token not found in headers under 'Authorization' (401)
I am sure other errors \(like an invalid token\) have the same behavior. How can I return a custom message with the proper status code?
Also, I don't know much about JWT, I have read that keeping the user logged in with the same token for an extended period of time is a bad idea, so how can I allow logging out and token expiration? Do you guys have any resources I need to read before making an API with weak security?
Thanks!
/r/flask
https://redd.it/8dqbhl
Django Rest Framework + Vue.js - Live notifications like on the FB
I have a social network project written in Django Rest Framework + Vue.js. I need to add new feature - live notifications like on the Facebook. For example:
* user A commented your post
* user K started fallowing you
and much more actions.
What is the best way to do this? Any suggestions are very welcome.
/r/django
https://redd.it/8dqbz0
I have a social network project written in Django Rest Framework + Vue.js. I need to add new feature - live notifications like on the Facebook. For example:
* user A commented your post
* user K started fallowing you
and much more actions.
What is the best way to do this? Any suggestions are very welcome.
/r/django
https://redd.it/8dqbz0
reddit
Django Rest Framework + Vue.js - Live notifications... • r/django
I have a social network project written in Django Rest Framework + Vue.js. I need to add new feature - live notifications like on the Facebook....
Creating a new molecule in ASE.
Been doing some searching on the internet and haven't found a good tutorial for my question:
I'm trying to model https://en.wikipedia.org/wiki/HMX using ASE try to optimize its geometry and it obviously isn't in the ase.collections.g2 database.
Can anyone point me in the right direction on where to get started making new molecules not in the ASE database?
Thank you and I apologize if this is in the incorrect subreddit.
/r/Python
https://redd.it/8dsgs6
Been doing some searching on the internet and haven't found a good tutorial for my question:
I'm trying to model https://en.wikipedia.org/wiki/HMX using ASE try to optimize its geometry and it obviously isn't in the ase.collections.g2 database.
Can anyone point me in the right direction on where to get started making new molecules not in the ASE database?
Thank you and I apologize if this is in the incorrect subreddit.
/r/Python
https://redd.it/8dsgs6
Django Custom User and AuthenticationForm Issue
https://stackoverflow.com/questions/49951014/django-custom-user-and-authenticationform
/r/djangolearning
https://redd.it/8dtosq
https://stackoverflow.com/questions/49951014/django-custom-user-and-authenticationform
/r/djangolearning
https://redd.it/8dtosq
Stackoverflow
Django Custom User and AuthenticationForm
I have found others' solutions helpful, but I still am having an issue.
Using a Custom User Model and also utilizing AuthenticationForm which said it support Custom User Models, I continuously rec...
Using a Custom User Model and also utilizing AuthenticationForm which said it support Custom User Models, I continuously rec...
Going from Matlab to Python?
I was wanting to hear some thoughts on how easy the transition is from Matlab to Python. I’d say I’m becoming sorta proficient in Matlab at this point, am I gonna have an easy time picking up Python with that background? I’m looking to mainly use it for stuff you’d see in engineering school like solving math problems and all that.
/r/Python
https://redd.it/8dtj7k
I was wanting to hear some thoughts on how easy the transition is from Matlab to Python. I’d say I’m becoming sorta proficient in Matlab at this point, am I gonna have an easy time picking up Python with that background? I’m looking to mainly use it for stuff you’d see in engineering school like solving math problems and all that.
/r/Python
https://redd.it/8dtj7k
reddit
Going from Matlab to Python? • r/Python
I was wanting to hear some thoughts on how easy the transition is from Matlab to Python. I’d say I’m becoming sorta proficient in Matlab at this...
How do I move my Django project to Linode?
I have a Django project that works fine on my local machine. The project hooks up to a Postgres database. I want to move it to a Linode Debian instance. But I cannot find clear instructions on how to move my project to the Linode server. Anyone have experience moving a Django project to Linode? Got some pointers?
/r/django
https://redd.it/8dtbim
I have a Django project that works fine on my local machine. The project hooks up to a Postgres database. I want to move it to a Linode Debian instance. But I cannot find clear instructions on how to move my project to the Linode server. Anyone have experience moving a Django project to Linode? Got some pointers?
/r/django
https://redd.it/8dtbim
reddit
How do I move my Django project to Linode? • r/django
I have a Django project that works fine on my local machine. The project hooks up to a Postgres database. I want to move it to a Linode Debian...
Issue: Text deletes when i type in front of it.
This just started happening a few days ago and I have never had this issue before. When I start typing code in front of a previous line of code it deletes it. For example, if a line has "print('Hello World!')" and I use my cursor to click in front of the word "print" and type "read", then it would be "readt('Hello World!')". Does anyone know how to fix this? Any help would be greatly appreciated.
/r/IPython
https://redd.it/8dxepo
This just started happening a few days ago and I have never had this issue before. When I start typing code in front of a previous line of code it deletes it. For example, if a line has "print('Hello World!')" and I use my cursor to click in front of the word "print" and type "read", then it would be "readt('Hello World!')". Does anyone know how to fix this? Any help would be greatly appreciated.
/r/IPython
https://redd.it/8dxepo
Reddit
reddit: the front page of the internet
r/IPython: If you have a question about IPython, (now Jupyter) the programming language written by scientists for scientists with an eye towards presentation, we want you here. If you have tips, Notebooks you want to share, or you want feedback we want you…
[Project] Monte-Carlo Search for Magic: The Gathering
https://hackernoon.com/monte-carlo-search-for-magic-the-gathering-6ca60750fcc6
/r/MachineLearning
https://redd.it/8e1ojv
https://hackernoon.com/monte-carlo-search-for-magic-the-gathering-6ca60750fcc6
/r/MachineLearning
https://redd.it/8e1ojv
Hacker Noon
Monte-Carlo Search for Magic: The Gathering
We’ve recently seen an emergence of strong artificial intelligence (AI) for difficult board games such as Go and Poker. There is yet to be…
User Session and Session Data
Is there any way to store session data based on a User's session?
i.e. `request.user['foo'] = 'bar'`
I know the above code doesn't work, so I was wondering if there is something built in where you could individually store data in sessions with each user? Or is there another to do something like this, because I need to use data across different views and I need to keep it separate from each User.
/r/djangolearning
https://redd.it/8e1v8q
Is there any way to store session data based on a User's session?
i.e. `request.user['foo'] = 'bar'`
I know the above code doesn't work, so I was wondering if there is something built in where you could individually store data in sessions with each user? Or is there another to do something like this, because I need to use data across different views and I need to keep it separate from each User.
/r/djangolearning
https://redd.it/8e1v8q
reddit
User Session and Session Data • r/djangolearning
Is there any way to store session data based on a User's session? i.e. `request.user['foo'] = 'bar'` I know the above code doesn't work, so I...
Impressed!
Fastest web development framework I have encountered till now.
Made a website in 24hours, which would have otherwise taken at least a week.
Thanks Flask!
/r/flask
https://redd.it/8e2o6e
Fastest web development framework I have encountered till now.
Made a website in 24hours, which would have otherwise taken at least a week.
Thanks Flask!
/r/flask
https://redd.it/8e2o6e
Reddit
reddit: the front page of the internet
r/flask: Flask is a Python micro-framework for web development. Flask is easy to get started and a great way to build web sites and web applications.