So I have a centos 6.6 on ec2.
Installed python 2.7, virtualenv for 2.7, pip-2.7 and created a virtualenv
install with my pip inside by virtualenv (2.7 all, promise) django 1.7.1
startproject works. I have my project. but:
python manage.py runserver 0.0.0.0:8080 / python manage.py migrate and everything that use manage.py gets this error:
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x1c43848>
Traceback (most recent call last):
File "/opt/webapps/env/lib/python2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper
fn(*args, **kwargs)
....
File "/opt/webapps/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql)
File "/opt/webapps/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 483, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "N": syntax error
I have no idea why this keeps happening. uninstalled & re-installed all but this error would stay anyway.
Google keeps suggesting south install / vagrant but I don't use them now.
Someone know what this thing is about?
BTW:
which python: /opt/webapps/env/bin/python
which pip: /opt/webapps/env/bin/pip
all in virtualenv in the right place and --version should 2.7
django.db.utils.OperationalError occures when validation of one of migrations failed. So, you should check all migrations of your project for incorrect SQL-syntax ("N").
Related
I have a question need your help~
I have a django program run in a vps(centos7,django2.2),it works well with Nginx+Uwsgi.
I edit three files(like a.py b.py c.py),and upload to the vps by winscp.exe,the program can't work now.
I found these logs in the uwsgi.log file.
File "/mnt/datasource/<privacy_hidden>/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 68, in <module>
check_sqlite_version()
File "/mnt/datasource/<privacy_hidden>/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 65, in check_sqlite_version
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
unable to load app 0 (mountpoint='') (callable not found or import error)
I wrote "sqlite3 --version" in centos7 shell, it show version = 3.30.1
I wrote "python >>> import sqlite3 >>>print sqlite3.sqlite_version" it show version=3.30.1
I wrote "python manage.py runserver --noreload 0.0.0.0:80",it works well, no info show sqlite error.
But the program can't work in uwsgi,I think the uwsgi.ini is correct.
What can I do ?
Thank you!
I think I have solved this question.
In centos shell:
> mv /usr/lib64/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6_old
> cp /usr/local/lib/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6
then it's ok
uwsgi has RPATH set. and its' /usr/lib64, and the old sqlite library is in this directory, you need to use the newer sqlite library in /usr/local/lib.
you could recompile uwsgi like this: sudo LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib" pip3 install uwsgi.
refrence: https://sourceexample.com/en/1c4153d4c3d4e65dac45/
I have a Django app working perfectly on my local Python 3.6 version and want to make sure that it will do so when installed elsewhere.
For this reason I created a virtualenv using precisely the same Python version which works fine globally, but without any packages:
virtualenv --no-site-packages --python=$(which python3.6) clear_env
source clear_env/bin/activate
Then I installed the requirements locally:
pip install -r requirements.txt
When I try to run the server, or even when I used the admin panel and make changes to the DB, everything works.
However, when I run the tests:
python manage.py test --nomigrations
I get the following error:
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL, `user_id` integer NOT NULL, `content_type_id` integer NULL, `objec' at line 1")
which tracebacks to:
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 312, in _query
db.query(q)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/connections.py", line 224, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL, `user_id` integer NOT NULL, `content_type_id` integer NULL, `objec' at line 1")
Note: I am using the --nomigrations flag in the testing to avoid this issue. This again works perfectly well in my global Python environment.
Initially I thought that the issue may be related to some missing linux MySQL/Python packages, similar to that issue. I remember that once I had to install something like libmysqlclient-dev python-dev and recompile the Python version to get it working.
However, provided that my virutalenv is using the same Python version which works globally, what could be the reason? And even more strange, why only the tests fail with that error and the runserver and everything else related to DB is working?
Solved. It was due to a possible bug in pipreqs, which I use to build requirements.txt. My global app version was using Django==2.0 and I use Mysql 5.5. For some reason, pipreqs has specified as a requirement Django==2.1.5 which supports only MySQL > 5.6, as stated here
As a result, when doing the fresh requirements installation in the virtualenv, the newer Django version was installed, which was not communicating properly with my local MySQL version.
Hey I'm trying to migrate my project using the command python manage.py makemigrations in django and I keep getting this error:
File "manage.py", line 14
) from exc
^
SyntaxError: invalid syntax
I have already found similar answers on it but nothing has worked. I am currently in the virtual environment already and changing the command to python3 manage.py makemigrations also prompts the same error.
The raise-from statement, or exception chaining, is only supported since Python 3.
Please upgrade your Python version to 3.0 or above in order to run this manage.py.
I could run the server on port 8000 but when i try to use 80 with
python manage.py runserver myip:80 I get:
You don't have permission to access that port.
If I use sudo python manage.py runserver myip:80 I get:
File "manage.py", line 14
) from exc
^
SyntaxError: invalid syntax
If I write python in the console I get version 3.5.5 and my env is activated.
EDIT:
Using sudo python3 manage.py runserver myip:80 I get:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
You are getting this because you aren't using Python 3. The easiest way to fix this is to create a virtualenv that uses python3 as it's python executable.
sudo pip3 install virtualenv
virtualenv -p python3 envname
workon envname
pip install django
pip install your_other_dependencies
Still, as others have said, running the Django webserver in a production environment is dicey at best, and spending some time setting up a Gunicorn/Nginx (or appropriate substitute) will pay dividends long term.
There are a couple of things going on here. First of all, only privileged users (e.g. root or other users via sudo) can bind to ports under 1024.
But more importantly, manage.py runserver should never be used in production:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
I strongly advise you to set up a proper web server instead. If you search for "EC2 Django" you'll find plenty of walkthroughs on how to do this properly.
I go through first django tutorial from djangoproject.com and at the very beginning of part 2, which is creating superuser when I run "python manage.py createsuperuser" I get the following message back:
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
I get the same message when I go on to create superuser after running syncdb.
I am working on Eclipse for Windows 7, and Django 1.7.1 together with Python 2.7.8.
When using the Git Bash and to correct the above error message try to append winpty i.e. for example:
$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):
You can create a superuser using django shell (python manage.py shell)
from django.contrib.auth.models import User
User.objects.create_superuser(username='YourUsername', password='hunter2', email='your#email.com')
if you are in virtualenv, cd into your virtualenv and activate it. then try these steps:
python manage.py syncdb --noinput
python manage.py migrate
python manage.py createsuperuser
Use "Windows PowerShell" or "Windows Cmd" and then use same command. Git command interface has some restriction.
I am a Windows10 user. I tried to run py manage.py createsuperuser command using Git Bash console, but error has been thrown. Then I switched Git Bash to native Windows Command Line with administrator privileges, and re-run command - it was working.
First run
$ django-admin startproject mysite
in cmd prompt,then apply migration by
cd mysite
mysite:
python manage.py makemigrations
then
python manage.py migrate
after that
python manage.py createsuperuser
From Django 3.0 you can do it without TTY
DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=psw \
python manage.py createsuperuser --email=admin#admin.com --noinput
also, you can set DJANGO_SUPERUSER_PASSWORD as the environment variable
If you are Windows user using GitBash terminal and trying to create super for admin it won't work instead of that use command prompt in administrative privilege it works
Gitbash terminal error
$ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run "manage.py createsuperuser" in your project to create one manually.
Error Resolved Using Command Prompt
python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address:
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
This might be helpful for others. Do Upvote for this if it works for you
Use this command :
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python manage.py runserver
Your error is probably:
[Error `You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, content types, sessions.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)`][1]
check you yo directory with Tree command:tree
Then run Make migration :
enter image description here
then create superuser with the python3 manage.py createsuperusercommand :