I'm working with a postgres database and the postgis extension. Now, after upgrading to Django 1.8, I'm getting this error while running manage.py migrate:
Traceback (most recent call last):
File "./manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/my-project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 91, in handle
connection.prepare_database()
File "/my-project/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 39, in prepare_database
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/my-project/env/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "spheroid" already exists
Versions
I'm using Postgres.app on OS X
psql (9.3.4)
SELECT PostGIS_version(); postgis_version 2.1 USE_GEOS=1 USE_PROJ=1USE_STATS=1
Django 1.8.2
Ok I solved it.
First I upgraded postgres and postgis with replacing Postgres.app with the newest one and upgrading brew packages. After this, I got the following error:
Traceback (most recent call last):
File "./manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/my-project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/my-project/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 91, in handle
connection.prepare_database()
File "/my-project/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 39, in prepare_database
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/my-project/env/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/my-project/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.InternalError: PostGIS is already installed in schema 'public', uninstall it first
Then I performed a "Hard Upgrade" as explained here http://postgis.net/docs/manual-2.1/postgis_installation.html#upgrading
All Steps (incl. Hard Upgrade)
pg_dump -U $PGUSER -Fc -b -v -f "your_db.backup" your_db
psql -U $PGUSER -d postgres -c "DROP DATABASE your_db;"
brew uninstall postgresql93 && brew install postgresql or brew upgrade postgresql
brew uninstall postgis15 && brew install postgis or brew upgrade postgis
Replace Postgres.app with newest one
pip uninstall psycopg2 && pip install psycopg2
psql -U $PGUSER -d postgres -c "CREATE DATABASE your_db;"
psql -U $PGUSER -d your_db -c "CREATE EXTENSION postgis;"
/usr/local/share/postgis/postgis_restore.pl your_db.backup | psql -U $PGUSER your_db 2> errors.txt
Related
I am using a docker file to handle my django app. I added user to the docker file as following:
FROM python:3.9-alpine3.13
LABEL maintainer="H.Bazai"
ENV PYTHONUNBUFFERED 1
COPY requirements.txt /tmp/
COPY requirements.dev.txt /tmp/
COPY app /app/
WORKDIR /app
EXPOSE 8000
ARG DEV=true
RUN rm -rf /var/cache/apk/*
RUN apk update && \
apk add --no-cache --virtual .build-deps \
build-base postgresql-dev musl-dev zlib-dev jpeg-dev && \
apk add --no-cache postgresql-client postgresql-dev jpeg && \
python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; then \
/py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp/* && \
apk --purge del .build-deps && \
adduser \
--disabled-password \
--no-create-home \
hbazai && \
mkdir -p /vol/web/media && \
mkdir -p /vol/web/static && \
chown -R hbazai:users /vol && \
chmod -R 755 /vol
ENV PATH="/py/bin:$PATH"
USER hbazai
Then I build it. "docker-compose build".
Up to here everything is ok.
Then when I use the bellow command to makemigration, I got the error of ' permission denied '.
The command:
docker-compose run --rm app sh -c "python manage.py makemigrations"
The Error:
Creating recepie-api-django_app_run ... done
Migrations for 'core':
core/migrations/0005_recipe_image.py
- Add field image to recipe
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/py/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 190, in handle
self.write_migration_files(changes)
File "/py/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 228, in write_migration_files
with open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: '/app/core/migrations/0005_recipe_image.py'
ERROR: 1
I would appreciate it if somebody can help me out.
I tried many things to give permission to the user of my ubuntu. (chown and chmode)
but I still get the error.
I am trying to run a snowsql query from the command line and also to pass config file while calling snowsql. On this blog there is an option presented:
–config PATH SnowSQL config file path.
I tried including this:
#!/bin/bash
snowsql -f training-data.sql \
-o quiet=true \
-o friendly=false \
-o header=false \
-config=./config
When I attempt ti run this I get:
No connection could be found for onfig=./config
It's odd because previously, I could swear the error message was (Note onfig Vs. nfig!):
No connection could be found for nfig=./config
How can I tell snowsql to use ./config as the config file when running the query?
You don’t need an equals sign. It should just be:
-config ./config
I have an sql file that contains below script that is ran via isql.
May I ask whats wrong with my output syntax? I am getting "Incorrect syntax near the keyword 'output'"
Sybase ASE version is 15.7
select * from tempdb..M3_STI_extracts_checking
output to employee.txt format ASCII
GO
isql offers the possibility to write the output into a file, if you set the option -o (Utility Commands Reference).
input.sql
select * from tempdb..M3_STI_extracts_checking
go
isql -i input.sql -o employee.txt
-J sets the charset (ASE 15.7 charsets)
isql -i input.sql -o employee.txt -J ascii_7
Was able to workaround by passing the variable from a shell script.
test.sh
output_file=test_file_'date +%m%d%Y'
${PARAM} isql << EOF
select * from tempdb..M3_STI_extracts_checking
GO > ${output_file}
EOF
I am trying to mount a file system using read only, but I am getting this error.
# cd Downloads
# ls
.localized
# mkdir /mnt/temp
mkdir: /mnt/temp: File exists
# mount -o ro,loop -t Ext3 system1 /mnt/temp
mount: exec /Library/Filesystems/Ext3.fs/Contents/Resources/mount_Ext3 for /mnt/temp: No such file or directory`
Why isn't /mnt/temp showing up? I am in sudo
I have a stored procedure in my local SQL Server that has one line output, line is about 1500 characters long. When I execute that stored procedure from sqlcmd (both PowerShell and CMD) the line gets cut off after 255 characters.
Here's the sqlcmd statement:
sqlcmd -S (local)\sqlexpress -E -d ReleaseTeam -Q "exit(exec[dbo].[SP_LOG_GETEMAILBODYHTML_TODAY])" -h-1 -o "D:\path\index.html"
How to fix it?